Skip to content

Commit e57a843

Browse files
committedJan 29, 2025
fix(dialect-wasm): fix official wasm database type
1 parent d73906f commit e57a843

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Kysely Sqlite Tools
22

3+
- [dialect](packages/dialect-generic-sqlite) for generic SQLite, support run in current or worker thread
34
- [dialect](packages/dialect-wasm) for `wasm`, run SQLite in browser
45
- [dialect](packages/dialect-sqlite-worker) for [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3), running sql in worker_thread
56
- [dialect](packages/dialect-wasqlite-worker) for [`wa-sqlite`](https://github.com/rhashimoto/wa-sqlite), running sql in web worker, store data in OPFS or IndexedDB

‎packages/dialect-bun-worker/src/worker/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function* iterateData(
1010
parameters?: readonly unknown[],
1111
): AsyncIterableIterator<Record<string, any>> {
1212
if (!('iterate' in stmt)) {
13-
throw new Error('Streaming not supported, please upgrade to Bun@^1.1.31')
13+
throw new Error('Streaming not supported, please upgrade to Bun@1.1.31 or later')
1414
}
1515
for (const row of stmt.iterate(...parameters || [] as any)) {
1616
yield row as any

‎packages/dialect-wasm/official-wasm.d.ts

-7
This file was deleted.

‎packages/dialect-wasm/src/official-wasm-dialect/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class OfficialWasmDialect extends GenericSqliteDialect {
6464
return db.selectObjects(sql, parameters as any)
6565
},
6666
run: () => ({
67-
insertId: BigInt(db.selectArray('SELECT last_insert_rowid()')[0]),
67+
insertId: BigInt((db.selectArray('SELECT last_insert_rowid()')?.[0] || 0) as number),
6868
numAffectedRows: BigInt(db.changes(false, true)),
6969
}),
7070
}),
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,60 @@
1-
import type { BaseDB } from '../types'
1+
export interface OfficialWasmDB {
22

3-
export type Option = {
4-
sql: string | string[]
5-
bind?: any[] | Record<string, any>
6-
returnValue?: 'resultRows' | 'saveSql' | 'this'
7-
resultRows?: any[]
8-
saveSql?: any[]
9-
columnNames?: string[]
10-
callback?: (row: any[], stmt: any) => void | false
11-
rowMode?: 'array' | 'object' | 'stmt'
12-
}
3+
/** Returns true if the database handle is open, else false. */
4+
isOpen: () => boolean
5+
6+
/** Throws if the given DB has been closed. */
7+
affirmOpen: () => this
8+
9+
/**
10+
* Finalizes all still-open statements which were opened by this object and
11+
* closes this database connection. This is a no-op if the db has already been
12+
* closed. After calling `close()`, {@link pointer} will resolve to
13+
* `undefined`, so that can be used to check whether the db instance is still
14+
* opened.
15+
*
16+
* If {@link onclose.before} is a function then it is called before any
17+
* close-related cleanup. If {@link onclose.after} is a function then it is
18+
* called after the db is closed but before auxiliary state like this.filename
19+
* is cleared.
20+
*
21+
* Both onclose handlers are passed this object as their only argument. If
22+
* this db is not opened, neither of the handlers are called. Any exceptions
23+
* the handlers throw are ignored because "destructors must not throw."
24+
*
25+
* Note that garbage collection of a db handle, if it happens at all, will
26+
* never trigger `close()`, so {@link onclose} handlers are not a reliable way
27+
* to implement close-time cleanup or maintenance of a db.
28+
*/
29+
close: () => void // ✓
30+
31+
/**
32+
* Returns the number of changes, as per `sqlite3_changes()` (if the first
33+
* argument is `false`) or `sqlite3_total_changes()` (if it's `true`). If the
34+
* 2nd argument is `true`, it uses `sqlite3_changes64()` or
35+
* `sqlite3_total_changes64()`, which will trigger an exception if this build
36+
* does not have `BigInt` support enabled.
37+
*/
38+
changes: (total?: boolean, sixtyFour?: boolean) => number
39+
40+
/**
41+
* Prepares the given SQL, `step()`s it one time, and returns an array
42+
* containing the values of the first result row. If it has no results,
43+
* `undefined` is returned. If passed a second argument other than
44+
* `undefined`, it is treated like an argument to
45+
* {@link PreparedStatement#bind}, so may be any type supported by that
46+
* function. Throws on error.
47+
*/
48+
selectArray: (sql: string, bind?: any[]) => any[] | undefined
49+
50+
/**
51+
* Works identically to {@link Database#selectArrays} except that each value in
52+
* the returned array is an object, as per the `"object"` rowMode option to
53+
* {@link Database#exec}.
54+
*/
55+
selectObjects: (
56+
sql: string,
57+
bind?: any[],
58+
) => { [columnName: string]: any }[]
1359

14-
export interface OfficialWasmDB extends BaseDB {
15-
changes: (isTotal: boolean, isBigint: boolean) => number | bigint
16-
selectArray: (sql: string, bind?: any[]) => any[]
17-
selectObjects: (sql: string, bind?: any[]) => any[]
1860
}

0 commit comments

Comments
 (0)
Please sign in to comment.