mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Refactor pragmas
This commit is contained in:
parent
d63de0ad0b
commit
f35d38d83b
1 changed files with 15 additions and 13 deletions
28
src/db.ts
28
src/db.ts
|
|
@ -55,24 +55,26 @@ interface UnattachedMediaRow {
|
||||||
uploaded_at: Date;
|
uploaded_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sqlite = new DenoSqlite3(Conf.dbPath);
|
|
||||||
|
|
||||||
setPragmas(sqlite, {
|
|
||||||
synchronous: 'normal',
|
|
||||||
temp_store: 'memory',
|
|
||||||
mmap_size: Conf.sqlite.mmapSize,
|
|
||||||
});
|
|
||||||
|
|
||||||
const db = new Kysely<DittoDB>({
|
const db = new Kysely<DittoDB>({
|
||||||
dialect: new DenoSqliteDialect({
|
dialect: new DenoSqliteDialect({
|
||||||
database: sqlite,
|
database: new DenoSqlite3(Conf.dbPath),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
function setPragmas(db: DenoSqlite3, pragmas: Record<string, string | number>) {
|
await Promise.all([
|
||||||
for (const [pragma, value] of Object.entries(pragmas)) {
|
setPragma(db, 'synchronous', 'normal'),
|
||||||
db.prepare(`PRAGMA ${pragma} = ${value}`).run();
|
setPragma(db, 'temp_store', 'memory'),
|
||||||
console.log(`PRAGMA ${pragma} = ${db.prepare(`PRAGMA ${pragma}`).value()}`);
|
setPragma(db, 'mmap_size', Conf.sqlite.mmapSize),
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** Set the PRAGMA and then read back its value to confirm. */
|
||||||
|
async function setPragma(db: Kysely<any>, pragma: string, value: string | number) {
|
||||||
|
await sql.raw(`PRAGMA ${pragma} = ${value}`).execute(db);
|
||||||
|
const result = (await sql.raw(`PRAGMA ${pragma}`).execute(db)).rows[0] as object;
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(result)) {
|
||||||
|
console.log(`PRAGMA ${key} = ${value};`);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue