refactor: migrate from node-sqlite3-wasm to better-sqlite3
Replace all db.run(sql, [params]) calls with db.prepare(sql).run(...params) across all source modules and test files. Also remove the node-sqlite3-wasm import from tests/db.test.ts and update the type annotation accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
import { Database } from 'node-sqlite3-wasm';
|
||||
import Database from 'better-sqlite3';
|
||||
import { migrate001 } from './migrations/001-initial';
|
||||
|
||||
let dbInstance: Database | null = null;
|
||||
let dbInstance: Database.Database | null = null;
|
||||
|
||||
export function initDb(path: string): Database {
|
||||
// node-sqlite3-wasm: pass undefined for in-memory DB
|
||||
const db = new Database(path === ':memory:' ? undefined : path);
|
||||
export function initDb(path: string): Database.Database {
|
||||
const db = new Database(path === ':memory:' ? ':memory:' : path);
|
||||
|
||||
// Enable WAL mode (file-based databases only, :memory: uses 'memory' mode)
|
||||
db.exec('PRAGMA journal_mode = WAL');
|
||||
// Enable foreign key constraints
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('foreign_keys = ON');
|
||||
|
||||
// Run migrations
|
||||
migrate001(db);
|
||||
@@ -19,7 +16,7 @@ export function initDb(path: string): Database {
|
||||
return db;
|
||||
}
|
||||
|
||||
export function getDb(): Database {
|
||||
export function getDb(): Database.Database {
|
||||
if (!dbInstance) {
|
||||
throw new Error('Database not initialized. Call initDb() first.');
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Database } from 'node-sqlite3-wasm';
|
||||
import Database from 'better-sqlite3';
|
||||
|
||||
export function migrate001(db: Database): void {
|
||||
db.exec(`
|
||||
|
||||
Reference in New Issue
Block a user