mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Use the SqliteWorker with our new Kysely dialect
This commit is contained in:
parent
01839fbcbf
commit
89b74217b6
3 changed files with 17 additions and 11 deletions
10
src/db.ts
10
src/db.ts
|
|
@ -1,9 +1,10 @@
|
||||||
import fs from 'node:fs/promises';
|
import fs from 'node:fs/promises';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { DenoSqlite3, DenoSqlite3Dialect, FileMigrationProvider, Kysely, Migrator } from '@/deps.ts';
|
import { PolySqliteDialect, FileMigrationProvider, Kysely, Migrator } from '@/deps.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { getPragma, setPragma } from '@/pragma.ts';
|
import { getPragma, setPragma } from '@/pragma.ts';
|
||||||
|
import { sqliteWorker } from '@/workers.ts';
|
||||||
|
|
||||||
interface DittoDB {
|
interface DittoDB {
|
||||||
events: EventRow;
|
events: EventRow;
|
||||||
|
|
@ -56,9 +57,12 @@ interface UnattachedMediaRow {
|
||||||
uploaded_at: Date;
|
uploaded_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await sqliteWorker.ready;
|
||||||
|
await sqliteWorker.open();
|
||||||
|
|
||||||
const db = new Kysely<DittoDB>({
|
const db = new Kysely<DittoDB>({
|
||||||
dialect: new DenoSqlite3Dialect({
|
dialect: new PolySqliteDialect({
|
||||||
database: new DenoSqlite3(Conf.dbPath),
|
database: sqliteWorker,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,13 @@ export {
|
||||||
FileMigrationProvider,
|
FileMigrationProvider,
|
||||||
type Insertable,
|
type Insertable,
|
||||||
Kysely,
|
Kysely,
|
||||||
|
type QueryResult,
|
||||||
|
type CompiledQuery,
|
||||||
Migrator,
|
Migrator,
|
||||||
type NullableInsertKeys,
|
type NullableInsertKeys,
|
||||||
sql,
|
sql,
|
||||||
} from 'npm:kysely@^0.26.3';
|
} from 'npm:kysely@^0.26.3';
|
||||||
export { DenoSqlite3Dialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v2.0.0/mod.ts';
|
export { PolySqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v2.0.0/mod.ts';
|
||||||
export { default as tldts } from 'npm:tldts@^6.0.14';
|
export { default as tldts } from 'npm:tldts@^6.0.14';
|
||||||
export * as cron from 'https://deno.land/x/deno_cron@v1.0.0/cron.ts';
|
export * as cron from 'https://deno.land/x/deno_cron@v1.0.0/cron.ts';
|
||||||
export { S3Client } from 'https://deno.land/x/s3_lite_client@0.6.1/mod.ts';
|
export { S3Client } from 'https://deno.land/x/s3_lite_client@0.6.1/mod.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
||||||
interface QueryResult {
|
import type { CompiledQuery, QueryResult } from '@/deps.ts';
|
||||||
rows: unknown[];
|
|
||||||
numAffectedRows: bigint;
|
|
||||||
insertId: bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SqliteWorker {
|
class SqliteWorker {
|
||||||
#path: string;
|
#path: string;
|
||||||
|
|
@ -29,9 +25,9 @@ class SqliteWorker {
|
||||||
return this.#call(['open', [this.#path]]);
|
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;
|
await this.ready;
|
||||||
return this.#call(['query', [sql, params]]);
|
return this.#call(['query', [sql, parameters]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#call<T>(msg: [string, unknown[]]): Promise<T> {
|
#call<T>(msg: [string, unknown[]]): Promise<T> {
|
||||||
|
|
@ -51,6 +47,10 @@ class SqliteWorker {
|
||||||
this.#worker.addEventListener('message', handleEvent);
|
this.#worker.addEventListener('message', handleEvent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async destroy() {
|
||||||
|
this.#worker.terminate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SqliteWorker;
|
export default SqliteWorker;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue