Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

athena-client

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

athena-client

a nodejs simple aws athena client

  • 2.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
decreased by-47.08%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

athena-client - a simple aws athena client for nodejs and typescript

This is version 2.x document. 1.x document is here

Install with:

npm install athena-client

Usage Example

Create Client

var clientConfig = {
    bucketUri: 's3://xxxx'
}

var awsConfig = {
    region: 'xxxx', 
}
 
var athena = require("athena-client")
var client = athena.createClient(clientConfig, awsConfig)

Receive result by Callback

client.execute('SELECT 1', function(err, data) {
    if (err) {
        return console.error(err)
    }
    console.log(data)
})

Receive result by Promise

client.execute('SELECT 1').toPromise()
.then(function(data) {
    console.log(data)
}).catch(function(err) {
    console.error(err)
})

Receive result by Stream

var stream = client.execute('SELECT 1').toStream()
stream.on('data', function(record) {
  console.log(record)
})
stream.on('query_end', function(queryExecution) {
  console.log(queryExecution)
})
stream.on('end', function() {
  console.log('end')
})
stream.on('error', function(e) {
  console.error(e)
})

API

athena = require("athena-client")

This module exposes the createClient method, which execute query to AWS Athena

client = athena.createClient([clientConfig], [awsConfig])

Returns a client instance attached to the account specified by the given clientConfig and awsConfig.

clientConfig object properties
PropertyDefaultDescription
bucketUriRequiredURI of S3 bucket for saving a query results file(.csv) and a metadata file (.csv.metadata)
pollingInterval1000Interval of polling sql results (ms)
queryTimeout0Timeout of query execution. 0 is no timeout
concurrentExecMax5The number of cuncurrent execution of query max. It should be set smaller than AWS Service limit(default is 5)
awsConfig object properties
PropertyDefaultDescription
regionRequiredYour Athena and S3 region
accessKeyIdundifinedYour IAM accessKeyId. This is optional
secretAccessKeyundifinedYour IAM secretAccessKey. This is optional

client.execute([query], [callback])

It will return the following result. If you want to know more about params of queryExecution, please refer to the aws-sdk document

{
    "records": [
        {"_col0:": "1"}
    ],
    "queryExecution": {
        "Query": "SELECT 1", 
        "QueryExecutionId": "55571bb9-8e4e-4274-90b7-8cffe4539c3c", 
        "ResultConfiguration": {
            "OutputLocation": "s3://bucket/55571bb9-8e4e-4274-90b7-8cffe4539c3c"
        }, 
        "Statistics": {
            "DataScannedInBytes": 0, 
            "EngineExecutionTimeInMillis": 137
        }, 
        "Status": {
            "CompletionDateTime": "2017-12-31T16:03:53.493Z", 
            "State": "SUCCEEDED", 
            "SubmissionDateTime": "2017-12-31T16:03:53.209Z"
        }
    }
}

client.execute([query]).toPromise()

It will return promise object to get result.

client.execute([query]).toStream()

It will return stream object to get result. If your query results are very large, we recommend using this stream.

// Get record one by one
stream.on('data', function(record) {
  console.log(record) // {"col1": "val1", "col2": "val2"}
})

// When query succeed, this event will emit.
stream.on('query_end', function(queryExecution) {
  console.log(queryExecution) // {"QueryExecutionId": "", ...}
})

stream.on('end', function() {
  console.log('end')
})
stream.on('error', function(e) {
  console.error(e)
})

Keywords

FAQs

Package last updated on 09 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc