Skip to content

Commit 94c9788

Browse files
yamatatsuclaude
andcommitted
docs: add CLAUDE.md for Claude Code guidance
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6e633b9 commit 94c9788

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
```bash
8+
pnpm test # run tests in watch mode
9+
pnpm test run # run tests once
10+
pnpm typecheck # type check (tsc --noEmit)
11+
pnpm build # build (unbuild → dist/)
12+
```
13+
14+
Run a single test by name:
15+
```bash
16+
pnpm vitest run test/index.test.ts -t "test name"
17+
```
18+
19+
Pre-commit hook runs `pnpm test run` and `pnpm typecheck` in parallel.
20+
21+
## Architecture
22+
23+
This is a small npm library (`@classmethod/athena-query`) that wraps the AWS SDK v3 Athena client and exposes results as an async generator.
24+
25+
Three source files:
26+
27+
- **`src/index.ts`** — re-exports `AthenaQuery` as default
28+
- **`src/athena-query.ts`** — public API: `AthenaQuery` class with single `query()` async generator method
29+
- **`src/helper.ts`** — internal AWS SDK calls and data transformation (not exported in public API)
30+
31+
### Query flow
32+
33+
`AthenaQuery.query(sql, options)` does three things in sequence:
34+
35+
1. `startQueryExecution` — calls `athena.startQueryExecution()`, returns `QueryExecutionId`
36+
2. `waitExecutionCompleted` — polls `athena.getQueryExecution()` every 200ms until state is `SUCCEEDED` or `FAILED`
37+
3. Paginated loop — calls `getQueryResults()` with `NextToken` until exhausted, `yield*`-ing each page's rows
38+
39+
### Data transformation in `helper.ts`
40+
41+
`cleanUpPaginatedDML` strips the header row (only present on the first page, i.e. when `NextToken` is absent) and converts each row to an object keyed by column name.
42+
43+
`addDataType` maps Athena column types to JS types:
44+
- `bigint``BigInt`
45+
- `integer`, `tinyint`, `smallint`, `int`, `float`, `double``Number`
46+
- `boolean``JSON.parse(value.toLowerCase())`
47+
- `json``JSON.parse(value)`
48+
- `varchar` and unknown types → `string`
49+
- Missing `VarCharValue` (null in Athena) → key is omitted from the result object
50+
51+
### `executionParameters` quoting
52+
53+
In `athena-query.ts`, parameters are formatted before passing to the SDK:
54+
- `string` → wrapped in single quotes (`'value'`)
55+
- `number` / `bigint``.toString()`
56+
57+
### Build output
58+
59+
`unbuild` produces dual CJS/ESM output in `dist/` with types, configured via `package.json` `exports` field.
60+
61+
### Tests
62+
63+
All tests live in `test/index.test.ts` and use `aws-sdk-client-mock` to mock `AthenaClient` without hitting AWS.

0 commit comments

Comments
 (0)