refactor(electrobun): simplify bun backend — extract db-utils, merge handlers
- db-utils.ts: shared openDb() (WAL, busy_timeout, foreign_keys, mkdirSync) - 5 DB modules use openDb() instead of duplicated PRAGMA boilerplate - bttask-db shares btmsg-db's Database handle (was duplicate connection) - misc-handlers.ts: 14 inline handlers extracted from index.ts - index.ts: 349→195 lines (only window controls remain inline) - updater.ts: removed dead getLastKnownVersion() - Net reduction: ~700 lines of duplicated boilerplate
This commit is contained in:
parent
2b1194c809
commit
f2e8b07d7f
10 changed files with 291 additions and 239 deletions
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
import { Database } from "bun:sqlite";
|
||||
import { homedir } from "os";
|
||||
import { mkdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { openDb } from "./db-utils.ts";
|
||||
|
||||
// ── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
@ -32,13 +32,7 @@ export class SearchDb {
|
|||
private db: Database;
|
||||
|
||||
constructor(dbPath?: string) {
|
||||
const path = dbPath ?? DB_PATH;
|
||||
const dir = join(path, "..");
|
||||
mkdirSync(dir, { recursive: true });
|
||||
|
||||
this.db = new Database(path);
|
||||
this.db.run("PRAGMA journal_mode = WAL");
|
||||
this.db.run("PRAGMA busy_timeout = 2000");
|
||||
this.db = openDb(dbPath ?? DB_PATH, { busyTimeout: 2000 });
|
||||
this.createTables();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue