Skip to content

Commit dae8d35

Browse files
committed
fix(kuzu-client): improve close to focus on connection
1 parent 97af9be commit dae8d35

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ describe("KuzuClient", { concurrency: false }, () => {
1616
);
1717
});
1818

19-
afterEach(() => {
19+
afterEach(async () => {
2020
try {
21+
await client.close();
2122
rmSync(testDbPath, { recursive: true, force: true });
2223
} catch {
2324
// Ignore cleanup errors
2425
}
2526
});
2627

27-
describe("constructor", () => {
28+
describe("constructor", { concurrency: false }, () => {
2829
it("creates a new database if createIfNotExists is true", () => {
2930
assert.doesNotThrow(() => {
3031
client = new KuzuClient({
@@ -64,7 +65,7 @@ describe("KuzuClient", { concurrency: false }, () => {
6465
});
6566
});
6667

67-
describe("static new method", () => {
68+
describe("static new method", { concurrency: false }, () => {
6869
it("creates a new instance using static method", () => {
6970
const instance = KuzuClient.new({
7071
path: testDbPath,
@@ -74,31 +75,31 @@ describe("KuzuClient", { concurrency: false }, () => {
7475
});
7576
});
7677

77-
describe("with active database", () => {
78+
describe("with active database", { concurrency: false }, () => {
7879
beforeEach(() => {
7980
client = new KuzuClient({
8081
path: testDbPath,
8182
createIfNotExists: true,
8283
});
8384
});
8485

85-
describe("connection getter", () => {
86+
describe("connection getter", { concurrency: false }, () => {
8687
it("returns the kuzu connection", () => {
8788
const conn = client.connection;
8889
assert.ok(conn);
8990
assert.ok(typeof conn.query === "function");
9091
});
9192
});
9293

93-
describe("query operations", () => {
94+
describe("query operations", { concurrency: false }, () => {
9495
beforeEach(async () => {
9596
// Create test schema
9697
await client.queryRaw`CREATE NODE TABLE Person(name STRING, age INT32, PRIMARY KEY (name))`;
9798
await client.queryRaw`CREATE NODE TABLE City(name STRING, population INT32, PRIMARY KEY (name))`;
9899
await client.queryRaw`CREATE REL TABLE LivesIn(FROM Person TO City)`;
99100
});
100101

101-
describe("query", () => {
102+
describe("query", { concurrency: false }, () => {
102103
it("executes a query and returns QueryResult", async () => {
103104
await client.queryRaw`CREATE (p:Person {name: "Alice", age: 30})`;
104105
const result = await client.queryRaw<{
@@ -114,9 +115,9 @@ describe("KuzuClient", { concurrency: false }, () => {
114115
it("handles template string with parameters", async () => {
115116
const name = "Bob";
116117
const age = 25;
117-
await client.queryRaw`CREATE (p:Person {name: ${name}, age: ${age}})`;
118+
await client.query`CREATE (p:Person {name: ${name}, age: ${age}})`;
118119

119-
const result = await client.queryRawOne<{
120+
const result = await client.queryOne<{
120121
name: string;
121122
age: number;
122123
}>`MATCH (p:Person {name: ${name}}) RETURN p.name as name, p.age as age`;
@@ -125,7 +126,7 @@ describe("KuzuClient", { concurrency: false }, () => {
125126
});
126127
});
127128

128-
describe("queryAll", () => {
129+
describe("queryAll", { concurrency: false }, () => {
129130
it("returns all rows from query", async () => {
130131
await client.queryRaw`CREATE (p1:Person {name: "Alice", age: 30})`;
131132
await client.queryRaw`CREATE (p2:Person {name: "Bob", age: 25})`;
@@ -150,7 +151,7 @@ describe("KuzuClient", { concurrency: false }, () => {
150151
});
151152
});
152153

153-
describe("queryOne", () => {
154+
describe("queryOne", { concurrency: false }, () => {
154155
it("returns first row from query", async () => {
155156
await client.queryRaw`CREATE (p1:Person {name: "Alice", age: 30})`;
156157
await client.queryRaw`CREATE (p2:Person {name: "Bob", age: 25})`;
@@ -172,13 +173,13 @@ describe("KuzuClient", { concurrency: false }, () => {
172173
});
173174
});
174175

175-
describe("complex queries", () => {
176+
describe("complex queries", { concurrency: false }, () => {
176177
it("handles node creation and retrieval", async () => {
177-
await client.queryRaw`CREATE (c:City {name: "New York", population: 8000000})`;
178-
await client.queryRaw`CREATE (p:Person {name: "Alice", age: 30})`;
179-
await client.queryRaw`MATCH (p:Person {name: "Alice"}), (c:City {name: "New York"}) CREATE (p)-[:LivesIn]->(c)`;
178+
await client.query`CREATE (c:City {name: "New York", population: 8000000})`;
179+
await client.query`CREATE (p:Person {name: "Alice", age: 30})`;
180+
await client.query`MATCH (p:Person {name: "Alice"}), (c:City {name: "New York"}) CREATE (p)-[:LivesIn]->(c)`;
180181

181-
const result = await client.queryRawOne<{
182+
const result = await client.queryOne<{
182183
person: string;
183184
city: string;
184185
}>`
@@ -221,7 +222,7 @@ describe("KuzuClient", { concurrency: false }, () => {
221222
});
222223
});
223224

224-
describe("error handling", () => {
225+
describe("error handling", { concurrency: false }, () => {
225226
beforeEach(() => {
226227
client = new KuzuClient({
227228
path: testDbPath,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class KuzuClient {
117117
* ```
118118
*/
119119
public async init() {
120-
if (!this.initPromise) this.initPromise = this.db.init();
120+
if (!this.initPromise) this.initPromise = this.conn.init();
121121
return this.initPromise;
122122
}
123123

@@ -145,7 +145,7 @@ export class KuzuClient {
145145
* ```
146146
*/
147147
public async close() {
148-
const promise = this.db.close();
148+
const promise = this.conn.close();
149149
this.initPromise = null;
150150
return promise;
151151
}

0 commit comments

Comments
 (0)