mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
28 lines
721 B
TypeScript
28 lines
721 B
TypeScript
/// <reference lib="webworker" />
|
|
|
|
import { Conf } from '@/config.ts';
|
|
import { type CompiledQuery, DenoSqlite3, expose, type QueryResult } from '@/deps.ts';
|
|
|
|
const db: DenoSqlite3 = new DenoSqlite3(Conf.dbPath);
|
|
|
|
db.exec(`
|
|
PRAGMA synchronous = normal;
|
|
PRAGMA temp_store = memory;
|
|
PRAGMA mmap_size = ${Conf.sqlite.mmapSize};
|
|
`);
|
|
|
|
export const SqliteWorker = {
|
|
executeQuery<R>({ sql, parameters }: CompiledQuery): QueryResult<R> {
|
|
if (!db) throw new Error('Database not open');
|
|
return {
|
|
rows: db.prepare(sql).all(...parameters as any[]) as R[],
|
|
numAffectedRows: BigInt(db.changes),
|
|
insertId: BigInt(db.lastInsertRowId),
|
|
};
|
|
},
|
|
destroy() {
|
|
db?.close();
|
|
},
|
|
};
|
|
|
|
expose(SqliteWorker);
|