@classmethod/athena-query
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

Athena-Query

Release CI npm version GitHub license

Athena-Query provide simple interface to get athena query results.

Athena-Query was inspired and forked from athena-express.

Warning Athena-Query support aws-sdk v3 only. So if you use aws-sdk v2, we recommend to use athena-express.

Installation

npm install @classmethod/athena-query @aws-sdk/client-athena
yarn add @classmethod/athena-query @aws-sdk/client-athena

Usage

Basic Usage

Athena-Query provide query() method as async generator function. So we can use it with for await () {},

import { Athena } from "@aws-sdk/client-athena";
import AthenaQuery from "@classmethod/athena-query";

const athena = new Athena({});
const athenaQuery = new AthenaQuery(athena);

for await (const item of athenaQuery.query("SELECT * FROM waf_logs;")) {
  console.log(item); // You can get all items across pagination.
}

And if you break loop out, Athena-Query don't call unnecessary pages of get-query-result api.

If you want to reduce the size of the queried data rather than the retrieved data, you can use the LIMIT clause.

Options

When you initialize AthenaQuery class, you can pass options to specify the query target.

const athenaQuery = new AthenaQuery(athena, {
  db: "test-db",
  workgroup: "test-workgroup",
  catalog: "test-catalog",
  outputLocation: "s3://path/to/query/bucket/",
});

When you query to Athena, you can pass options for query.

const resultGen = athenaQuery.query(
  `
    SELECT * FROM waf_logs
    WHERE name = ? AND groupId = ? AND score > ?;
  `,
  {
    executionParameters: ["test", 123, 456n],
  },
);

Package Sidebar

Install

npm i @classmethod/athena-query

Weekly Downloads

617

Version

1.4.0

License

MIT

Unpacked Size

19.8 kB

Total Files

8

Last publish

Collaborators

  • cm-nishida.masayuki
  • yamatatsu
  • otas
  • mchello