trips) migrate sqlite and runtime to bun
Some checks failed
PR Checks / lint-test-and-docker-build (pull_request) Has been cancelled

This commit is contained in:
2026-02-20 23:05:22 -05:00
parent 982c84cc33
commit e28741a4f1
7 changed files with 33 additions and 110 deletions

View File

@@ -1,23 +1,28 @@
import BetterSqlite3 from 'better-sqlite3';
import { Database as BunSqliteDatabase } from 'bun:sqlite';
import type { Database } from './types.js';
export function createSqliteDb(url: string): Database {
// Strip the "file:" prefix if present
const path = url.startsWith('file:') ? url.slice(5) : url;
const db = new BetterSqlite3(path);
const db = new BunSqliteDatabase(path);
// Enable WAL mode for better concurrent read performance
db.pragma('journal_mode = WAL');
try {
db.exec('PRAGMA journal_mode = WAL');
} catch {
// This can fail when multiple processes initialize the same DB concurrently.
}
return {
run(sql, params = []) {
db.prepare(sql).run(params);
db.query(sql).run(...params);
},
get<T = Record<string, unknown>>(sql: string, params: unknown[] = []) {
return db.prepare(sql).get(params) as T | undefined;
const row = db.query(sql).get(...params);
return (row === null ? undefined : row) as T | undefined;
},
all<T = Record<string, unknown>>(sql: string, params: unknown[] = []) {
return db.prepare(sql).all(params) as T[];
return db.query(sql).all(...params) as T[];
},
close() {
db.close();