Skip to content

Commit af2f74b

Browse files
authored
feat: allow to give number and BigInt to executionParameters (#16)
1 parent 0a41ab9 commit af2f74b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/athena-query.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,26 @@ export class AthenaQuery {
1515

1616
async *query(
1717
sql: string,
18-
options?: { executionParameters?: string[]; maxResults?: number }
18+
options?: {
19+
executionParameters?: (string | number | BigInt)[];
20+
maxResults?: number;
21+
}
1922
): AsyncGenerator<helpers.AtheneRecordData, void, undefined> {
2023
const QueryExecutionId = await helpers.startQueryExecution({
2124
athena: this.athena,
2225
sql,
23-
executionParameters: options?.executionParameters,
26+
executionParameters: options?.executionParameters?.map((param) => {
27+
const typeOfParam = typeof param;
28+
switch (typeOfParam) {
29+
case "bigint":
30+
case "number":
31+
return param.toString();
32+
case "string":
33+
return `'${param}'`;
34+
default:
35+
throw new Error(`${typeOfParam} type is not allowed.`);
36+
}
37+
}),
2438
...this.options,
2539
});
2640

test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ test("pass args to sdk", async () => {
251251
catalog: "test-catalog",
252252
});
253253
const resultGen = athenaQuery.query("SELECT test FROM test;", {
254-
executionParameters: ["'test'", "123"],
254+
executionParameters: ["test", 123, 456n],
255255
maxResults: 100,
256256
});
257257

@@ -261,7 +261,7 @@ test("pass args to sdk", async () => {
261261
athenaMock.commandCalls(StartQueryExecutionCommand)[0].args[0].input
262262
).toEqual({
263263
QueryString: "SELECT test FROM test;",
264-
ExecutionParameters: ["'test'", "123"],
264+
ExecutionParameters: ["'test'", "123", "456"],
265265
WorkGroup: "test-workgroup",
266266
QueryExecutionContext: {
267267
Catalog: "test-catalog",

0 commit comments

Comments
 (0)