Skip to content

Commit 64ed0c2

Browse files
committed
fix(dialect-wasm): finalize wa-sqlite str_new
1 parent 4225fa3 commit 64ed0c2

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/dialect-wasm/src/wasqlite-dialect/driver.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,26 @@ class WaSqliteConnection extends BaseSqliteConnection {
3737
async query(sql: string, params?: any[] | undefined): QueryReturn {
3838
const rows: any[] = []
3939
const str = this.sqlite.str_new(this.db, sql)
40-
const prepared = await this.sqlite.prepare_v2(this.db, this.sqlite.str_value(str))
40+
try {
41+
const prepared = await this.sqlite.prepare_v2(this.db, this.sqlite.str_value(str))
4142

42-
if (prepared) {
43-
const stmt = prepared.stmt
44-
try {
45-
params?.length && this.sqlite.bind_collection(stmt, params as [])
43+
if (prepared) {
44+
const stmt = prepared.stmt
45+
try {
46+
params?.length && this.sqlite.bind_collection(stmt, params as [])
4647

47-
const cols = this.sqlite.column_names(stmt)
48+
const cols = this.sqlite.column_names(stmt)
4849

49-
while ((await this.sqlite.step(stmt)) === 100/* SQLITE_ROW */) {
50-
const row = this.sqlite.row(stmt)
51-
rows.push(Object.fromEntries(cols.map((key, i) => [key, row[i]])))
50+
while ((await this.sqlite.step(stmt)) === 100/* SQLITE_ROW */) {
51+
const row = this.sqlite.row(stmt)
52+
rows.push(Object.fromEntries(cols.map((key, i) => [key, row[i]])))
53+
}
54+
} finally {
55+
await this.sqlite.finalize(stmt)
5256
}
53-
} finally {
54-
await this.sqlite.finalize(stmt)
5557
}
58+
} finally {
59+
this.sqlite.str_finish(str)
5660
}
5761
return rows
5862
}

packages/dialect-wasm/src/wasqlite-dialect/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface WaSqliteDatabase {
77
export interface Sqlite {
88
str_new: (db: number, sql: string) => number
99
str_value: (str: number) => number
10+
str_finish: (str: number) => void
1011
prepare_v2: (db: number, sql: number) => Promise<{ stmt: number; sql: number } | null>
1112
step: (stmt: number) => Promise<number>
1213
finalize: (stmt: number) => Promise<number>

0 commit comments

Comments
 (0)