Skip to content

Commit 40f7c7f

Browse files
committed
feat(kuzu): switch to proper string interpolation
1 parent 9587e82 commit 40f7c7f

2 files changed

Lines changed: 11 additions & 39 deletions

File tree

packages/kuzu-client/src/kuzu-client.lib.test.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ describe("KuzuClient", { concurrency: false }, () => {
113113

114114
it("handles template string with parameters", async () => {
115115
const name = "Bob";
116-
const age = "25";
117-
await client.query`CREATE (p:Person {name: "${name}", age: ${age}})`;
116+
const age = 25;
117+
await client.query`CREATE (p:Person {name: ${name}, age: ${age}})`;
118118

119119
const result = await client.queryOne<{
120120
name: string;
121121
age: number;
122-
}>`MATCH (p:Person {name: "${name}"}) RETURN p.name as name, p.age as age`;
122+
}>`MATCH (p:Person {name: ${name}}) RETURN p.name as name, p.age as age`;
123123
assert.equal(result?.name, "Bob");
124124
assert.equal(result?.age, 25);
125125
});
@@ -219,36 +219,6 @@ describe("KuzuClient", { concurrency: false }, () => {
219219
});
220220
});
221221
});
222-
223-
describe("extension methods", () => {
224-
beforeEach(() => {
225-
client = new KuzuClient({
226-
path: testDbPath,
227-
createIfNotExists: true,
228-
});
229-
});
230-
231-
describe("getLoadedExtensions", () => {
232-
void it.skip("returns list of loaded extensions", async () => {
233-
await client.getLoadedExtensions();
234-
assert.ok(true);
235-
});
236-
});
237-
238-
describe("loadExtension", () => {
239-
void it.skip("loads an extension if not already loaded", async () => {
240-
// Skipping extension loading test as it's environment-dependent
241-
await client.loadExtension("json");
242-
assert.ok(true);
243-
});
244-
245-
void it.skip("does not reload already loaded extensions", async () => {
246-
// Skipping as it depends on environment
247-
await client.getLoadedExtensions();
248-
assert.ok(true);
249-
});
250-
});
251-
});
252222
});
253223

254224
describe("error handling", () => {

packages/kuzu-client/src/kuzu-client.lib.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,21 @@ export class KuzuClient {
106106
* console.log(result.getNext());
107107
* }
108108
* ```
109-
*
110-
* @warning String interpolation does not automatically add quotes for string values.
111-
* Use quotes in the template: `WHERE name = "${name}"`
112109
*/
113110
public async query<T = unknown>(
114111
template: TemplateStringsArray,
115-
...args: string[]
112+
...args: any[]
116113
) {
117114
// If the first query fails, it crashes the database, so we need initialize it manually before executing the query so that it throws instead
118115
if (!this.initPromise) this.initPromise = this.db.init();
119116
await this.initPromise;
120-
const query = t(template, ...args);
121-
return await this.conn.query<T>(query);
117+
const idsArray = args.map((_, index) => `$arg${index}`);
118+
const query = t(template, ...idsArray);
119+
const preparedStatement = await this.conn.prepare(query);
120+
const argsMap = Object.fromEntries(
121+
args.map((arg, index) => [`arg${index}`, arg]),
122+
);
123+
return await this.conn.execute<T>(preparedStatement, argsMap);
122124
}
123125

124126
/**

0 commit comments

Comments
 (0)