Merge branch 'sqlite3' into 'main'

Switch main database to Deno SQLite3

See merge request soapbox-pub/ditto!54
This commit is contained in:
Alex Gleason 2023-10-11 21:26:53 +00:00
commit fe99e4a053
4 changed files with 11 additions and 10 deletions

View File

@ -2,12 +2,12 @@
"$schema": "https://deno.land/x/deno@v1.32.3/cli/schemas/config-file.v1.json", "$schema": "https://deno.land/x/deno@v1.32.3/cli/schemas/config-file.v1.json",
"lock": false, "lock": false,
"tasks": { "tasks": {
"start": "deno run --allow-read --allow-write=data --allow-env --allow-net --allow-sys src/server.ts", "start": "deno run -A --unstable src/server.ts",
"dev": "deno run --allow-read --allow-write=data --allow-env --allow-net --allow-sys --watch src/server.ts", "dev": "deno run -A --unstable --watch src/server.ts",
"debug": "deno run --allow-read --allow-write=data --allow-env --allow-net --allow-sys --inspect src/server.ts", "debug": "deno run -A --unstable --inspect src/server.ts",
"test": "DB_PATH=\":memory:\" deno test --allow-read --allow-write=data --allow-env src", "test": "DB_PATH=\":memory:\" deno test -A --unstable src",
"check": "deno check src/server.ts", "check": "deno check src/server.ts",
"relays:sync": "deno run -A scripts/relays.ts sync" "relays:sync": "deno run -A --unstable scripts/relays.ts sync"
}, },
"imports": { "imports": {
"@/": "./src/", "@/": "./src/",

View File

@ -1,7 +1,7 @@
import fs from 'node:fs/promises'; import fs from 'node:fs/promises';
import path from 'node:path'; import path from 'node:path';
import { DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator, Sqlite } from '@/deps.ts'; import { DenoSqlite3, DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator } from '@/deps.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
interface DittoDB { interface DittoDB {
@ -57,7 +57,7 @@ interface UnattachedMediaRow {
const db = new Kysely<DittoDB>({ const db = new Kysely<DittoDB>({
dialect: new DenoSqliteDialect({ dialect: new DenoSqliteDialect({
database: new Sqlite(Conf.dbPath), database: new DenoSqlite3(Conf.dbPath),
}), }),
}); });

View File

@ -1,5 +1,5 @@
import { db } from '@/db.ts'; import { db } from '@/db.ts';
import { type Event, SqliteError } from '@/deps.ts'; import { type Event } from '@/deps.ts';
import { isParameterizedReplaceableKind } from '@/kinds.ts'; import { isParameterizedReplaceableKind } from '@/kinds.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { EventData } from '@/types.ts'; import { EventData } from '@/types.ts';
@ -64,7 +64,7 @@ function insertEvent(event: Event, data: EventData): Promise<void> {
]); ]);
}).catch((error) => { }).catch((error) => {
// Don't throw for duplicate events. // Don't throw for duplicate events.
if (error instanceof SqliteError && error.code === 19) { if (error.message.includes('UNIQUE constraint failed')) {
return; return;
} else { } else {
throw error; throw error;

View File

@ -56,6 +56,7 @@ export {
DB as Sqlite, DB as Sqlite,
SqliteError, SqliteError,
} from 'https://raw.githubusercontent.com/alexgleason/deno-sqlite/325f66d8c395e7f6f5ee78ebfa42a0eeea4a942b/mod.ts'; } from 'https://raw.githubusercontent.com/alexgleason/deno-sqlite/325f66d8c395e7f6f5ee78ebfa42a0eeea4a942b/mod.ts';
export { Database as DenoSqlite3 } from 'https://deno.land/x/sqlite3@0.9.1/mod.ts';
export * as dotenv from 'https://deno.land/std@0.198.0/dotenv/mod.ts'; export * as dotenv from 'https://deno.land/std@0.198.0/dotenv/mod.ts';
export { export {
FileMigrationProvider, FileMigrationProvider,
@ -65,7 +66,7 @@ export {
type NullableInsertKeys, type NullableInsertKeys,
sql, sql,
} from 'npm:kysely@^0.25.0'; } from 'npm:kysely@^0.25.0';
export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v1.0.1/mod.ts'; export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sqlite/-/raw/v1.1.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';