SqliteWorker: return query result instead of rows for query
This commit is contained in:
parent
e601c43197
commit
ae56d059b1
|
@ -1,3 +1,9 @@
|
||||||
|
interface QueryResult {
|
||||||
|
rows: unknown[];
|
||||||
|
numAffectedRows: bigint;
|
||||||
|
insertId: bigint;
|
||||||
|
}
|
||||||
|
|
||||||
class SqliteWorker {
|
class SqliteWorker {
|
||||||
#path: string;
|
#path: string;
|
||||||
#worker: Worker;
|
#worker: Worker;
|
||||||
|
@ -23,7 +29,7 @@ class SqliteWorker {
|
||||||
return this.#call(['open', [this.#path]]);
|
return this.#call(['open', [this.#path]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async query(sql: string, params?: any): Promise<unknown[]> {
|
async query(sql: string, params?: any): Promise<QueryResult> {
|
||||||
await this.ready;
|
await this.ready;
|
||||||
return this.#call(['query', [sql, params]]);
|
return this.#call(['query', [sql, params]]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,11 @@ function handleOpen(path: string): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleQuery(sql: string, params: any[] = []) {
|
function handleQuery(sql: string, params: any[] = []) {
|
||||||
return db.prepare(sql).all(...params);
|
return {
|
||||||
|
rows: db.prepare(sql).all(...params),
|
||||||
|
numAffectedRows: BigInt(db.changes),
|
||||||
|
insertId: BigInt(db.lastInsertRowId),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addEventListener('message', (event: MessageEvent<[string, Msg]>) => {
|
self.addEventListener('message', (event: MessageEvent<[string, Msg]>) => {
|
||||||
|
|
Loading…
Reference in New Issue