Remove pragma.ts

This commit is contained in:
Alex Gleason 2024-04-19 15:19:49 -05:00
parent 2e41254507
commit 450acddc32
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 4 additions and 20 deletions

View File

@ -1,7 +1,6 @@
import { Conf } from '@/config.ts';
import { DittoTables } from '@/db/DittoTables.ts';
import { Kysely, PolySqliteDialect } from '@/deps.ts';
import { setPragma } from '@/pragma.ts';
import { Kysely, PolySqliteDialect, sql } from '@/deps.ts';
import SqliteWorker from '@/workers/sqlite.ts';
export class DittoSQLite {
@ -20,9 +19,9 @@ export class DittoSQLite {
// Set PRAGMA values.
await Promise.all([
setPragma(this.db, 'synchronous', 'normal'),
setPragma(this.db, 'temp_store', 'memory'),
setPragma(this.db, 'mmap_size', Conf.sqlite.mmapSize),
sql`PRAGMA synchronous = normal`.execute(this.db),
sql`PRAGMA temp_store = memory`.execute(this.db),
sql.raw(`PRAGMA mmap_size = ${Conf.sqlite.mmapSize}`).execute(this.db),
]);
}
return this.db;

View File

@ -1,15 +0,0 @@
import { type Kysely, sql } from '@/deps.ts';
/** Set the PRAGMA and then read back its value to confirm. */
function setPragma(db: Kysely<any>, pragma: string, value: string | number) {
return sql.raw(`PRAGMA ${pragma} = ${value}`).execute(db);
}
/** Get value of PRAGMA from the database. */
async function getPragma(db: Kysely<any>, pragma: string) {
const result = await sql.raw(`PRAGMA ${pragma}`).execute(db);
const row = result.rows[0] as Record<string, unknown> | undefined;
return row?.[pragma];
}
export { getPragma, setPragma };