Use the SqliteWorker with our new Kysely dialect

This commit is contained in:
Alex Gleason
2023-12-01 18:15:39 -06:00
parent 01839fbcbf
commit 89b74217b6
3 changed files with 17 additions and 11 deletions

View File

@@ -1,8 +1,4 @@
interface QueryResult {
rows: unknown[];
numAffectedRows: bigint;
insertId: bigint;
}
import type { CompiledQuery, QueryResult } from '@/deps.ts';
class SqliteWorker {
#path: string;
@@ -29,9 +25,9 @@ class SqliteWorker {
return this.#call(['open', [this.#path]]);
}
async query(sql: string, params?: any): Promise<QueryResult> {
async executeQuery<R>({ sql, parameters }: CompiledQuery): Promise<QueryResult<R>> {
await this.ready;
return this.#call(['query', [sql, params]]);
return this.#call(['query', [sql, parameters]]);
}
#call<T>(msg: [string, unknown[]]): Promise<T> {
@@ -51,6 +47,10 @@ class SqliteWorker {
this.#worker.addEventListener('message', handleEvent);
});
}
async destroy() {
this.#worker.terminate();
}
}
export default SqliteWorker;