@classmethod/athena-query

中文文档
1.4.0发布于 2024/03/31MITTypeScriptESM + CJS零依赖近 30 天下载 1万

Athena-Query makes it easier to execute SQL queries on Amazon Athena by consolidating & abstracting several methods in the AWS SDK

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Basic Usage
  4. Options

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],
  },
);

版本与发布记录

@classmethod/athena-query 共发布 18 个版本,首次发布于 2022/11/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2024/03/312 年前
1.3.02024/03/312 年前
1.2.02023/11/093 年前
1.1.02023/03/063 年前
1.0.12022/12/033 年前
1.0.02022/12/033 年前

关于 @classmethod/athena-query 的常见问题

@classmethod/athena-query 是什么?

Athena-Query makes it easier to execute SQL queries on Amazon Athena by consolidating & abstracting several methods in the AWS SDK

如何安装 @classmethod/athena-query?

在项目目录运行 npm install @classmethod/athena-query,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@aws-sdk/client-athena(^3.x.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@classmethod/athena-query 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@classmethod/athena-query 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@classmethod/athena-query 可以商用吗?

@classmethod/athena-query 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@classmethod/athena-query 的下载量有多少?

根据 npm 官方下载统计,@classmethod/athena-query 在 2026/10/10 – 2026/11/08 这 30 天内被下载 10,049 次,日均约 335 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@classmethod/athena-query 还在维护吗?

最新版本 1.4.0 发布于 2024/03/31(2 年前);至今共发布 18 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/11/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。