{"id":22355433,"url":"https://github.com/koteiito/node-athena","last_synced_at":"2025-04-05T12:07:46.967Z","repository":{"id":22706552,"uuid":"97085644","full_name":"KoteiIto/node-athena","owner":"KoteiIto","description":"a nodejs simple aws athena client","archived":false,"fork":false,"pushed_at":"2021-05-12T11:31:40.000Z","size":187,"stargazers_count":105,"open_issues_count":12,"forks_count":73,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-14T08:35:28.303Z","etag":null,"topics":["athena","athena-client","aws","aws-athena","aws-lambda","javascript","lambda","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KoteiIto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-13T06:00:54.000Z","updated_at":"2023-07-27T12:02:31.000Z","dependencies_parsed_at":"2022-08-07T10:16:05.514Z","dependency_job_id":null,"html_url":"https://github.com/KoteiIto/node-athena","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoteiIto%2Fnode-athena","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoteiIto%2Fnode-athena/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoteiIto%2Fnode-athena/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KoteiIto%2Fnode-athena/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KoteiIto","download_url":"https://codeload.github.com/KoteiIto/node-athena/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332609,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["athena","athena-client","aws","aws-athena","aws-lambda","javascript","lambda","nodejs","typescript"],"created_at":"2024-12-04T14:06:31.205Z","updated_at":"2025-04-05T12:07:46.948Z","avatar_url":"https://github.com/KoteiIto.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/KoteiIto/node-athena.svg?branch=master)](https://travis-ci.org/KoteiIto/node-athena)\n[![Coverage Status](https://coveralls.io/repos/github/KoteiIto/node-athena/badge.svg?branch=master)](https://coveralls.io/github/KoteiIto/node-athena?branch=master)\n\nathena-client - a  simple aws athena client for nodejs and typescript\n===========================\nThis is version 2.x document. 1.x document is [here](https://github.com/KoteiIto/node-athena/tree/1.x)\n\nInstall with:\n\n    npm install athena-client\n\n## Usage Example\n\n### Create Client\n```js\nvar clientConfig = {\n    bucketUri: 's3://xxxx'\n}\n\nvar awsConfig = {\n    region: 'xxxx', \n}\n \nvar athena = require(\"athena-client\")\nvar client = athena.createClient(clientConfig, awsConfig)\n```\n\n### Receive result by Callback\n```js\nclient.execute('SELECT 1', function(err, data) {\n    if (err) {\n        return console.error(err)\n    }\n    console.log(data)\n})\n```\n\n### Receive result by Promise\n```js \nclient.execute('SELECT 1').toPromise()\n.then(function(data) {\n    console.log(data)\n})\n.catch(function(err) {\n    console.error(err)\n})\n```\n\n### Receive result by Stream\n```js\nvar stream = client.execute('SELECT 1').toStream()\nstream.on('data', function(record) {\n  console.log(record)\n})\nstream.on('query_end', function(queryExecution) {\n  console.log(queryExecution)\n})\nstream.on('end', function() {\n  console.log('end')\n})\nstream.on('error', function(e) {\n  console.error(e)\n})\n```\n\n# API\n### athena = require(\"athena-client\")\nThis module exposes the `createClient` and `setConcurrentExecMax` method, which execute query to AWS Athena.\n\n### client = athena.createClient([_clientConfig_], [_awsConfig_])\nReturns a client instance attached to the account specified by the given `clientConfig` and `awsConfig`.\n\n### athena.setConcurrentExecMax([_concurrentExecMax_])\nSet the number of cuncurrent execution of query max. It should be set `smaller than AWS Service limit` (default is 5).\n\n#### `clientConfig` object properties\n| Property  | Default   | Description |\n|-----------|-----------|-------------|\n| bucketUri      | __Required__ | URI of S3 bucket for saving a query results file (*.csv) and a metadata file (*.csv.metadata) |\n| pollingInterval      | 1000  |  Optional. Interval of polling sql results (ms) |\n| queryTimeout      | 0      | Optional. Timeout of query execution.  `0` is no timeout |\n| database | 'default' | Optional. The name of the database within which the query executes |\n| baseRetryWait | 200 | Optional. Used to calculate retry timeout for a particular query execution request |\n| retryWaitMax | 10000 | Optional. Maximum retry timeout for starting a new query execution |\n| retryCountMax | 10 | Optional. Maximum number of retry attempts for a particular query execution request |\n| execRightCheckInterval | 100 | Optional. Timeout when number of maximum concurrent requests is exceeded |\n| encryptionOption | undefined | Optional. Indicates the S3 encryption option used to encrypt the query results. Possible values include: `SSE_S3`, `SSE_KMS`, or `CSE_KMS` |\n| encryptionKmsKey | undefined | Optional but required if `encryptionOption` is set to `SSE_KMS` or `CSE_KMS`. Value is the KMS key ARN or ID |\n| skipFetchResult | false | Optional.　If true, do not return the result of the query when the athena query is finished. This option is used for [CTAS](https://docs.aws.amazon.com/athena/latest/ug/ctas.html) |\n| concurrentExecMax | 5 | DEPRECATED. Use `athena.setConcurrentExecMax()` instead |\n| workGroup | 'primary' | Optional. The name of the workgroup within which the query executes\n\n#### `awsConfig` object properties\n| Property  | Default   | Description |\n|-----------|-----------|-------------|\n| region        | __Required__ | Your Athena and S3 region |\n| accessKeyId      | undefined  | Optional. Your IAM `accessKeyId` |\n| secretAccessKey      | undefined | Optional. Your IAM `secretAccessKey` |\n\n### client.execute([_query_], [_callback_])\nIt will return the following result.\nIf you want to know more about params of `queryExecution`, please refer to the `aws-sdk` [document](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Athena.html#getQueryExecution-property)  \n\n```json\n{\n    \"records\": [\n        {\"_col0:\": \"1\"}\n    ],\n    \"queryExecution\": {\n        \"Query\": \"SELECT 1\", \n        \"QueryExecutionId\": \"55571bb9-8e4e-4274-90b7-8cffe4539c3c\", \n        \"ResultConfiguration\": {\n            \"OutputLocation\": \"s3://bucket/55571bb9-8e4e-4274-90b7-8cffe4539c3c\"\n        }, \n        \"Statistics\": {\n            \"DataScannedInBytes\": 0, \n            \"EngineExecutionTimeInMillis\": 137\n        }, \n        \"Status\": {\n            \"CompletionDateTime\": \"2017-12-31T16:03:53.493Z\", \n            \"State\": \"SUCCEEDED\", \n            \"SubmissionDateTime\": \"2017-12-31T16:03:53.209Z\"\n        }\n    }\n}\n```\n\n### client.execute([_query_]).toPromise()\nReturns a `Promise` that resolves the result of your query.\n\n### client.execute([_query_]).toStream()\nReturns a `Stream` to buffer the results of your query. This method is recommended for **large** result sets.\n\n```js\n// Get record one by one\nstream.on('data', function(record) {\n  console.log(record) // {\"col1\": \"val1\", \"col2\": \"val2\"}\n})\n\n// When query succeed, this event will emit.\nstream.on('query_end', function(queryExecution) {\n  console.log(queryExecution) // {\"QueryExecutionId\": \"\", ...}\n})\n\nstream.on('end', function() {\n  console.log('end')\n})\nstream.on('error', function(e) {\n  console.error(e)\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoteiito%2Fnode-athena","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoteiito%2Fnode-athena","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoteiito%2Fnode-athena/lists"}