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:
Hibryda 2026-03-23 21:09:57 +01:00
parent 2b1194c809
commit f2e8b07d7f
10 changed files with 291 additions and 239 deletions

View file

@ -6,8 +6,8 @@
import { Database } from "bun:sqlite";
import { homedir } from "os";
import { mkdirSync } from "fs";
import { join } from "path";
import { openDb } from "./db-utils.ts";
// ── DB path ──────────────────────────────────────────────────────────────────
@ -103,10 +103,7 @@ export class SettingsDb {
private db: Database;
constructor() {
// Ensure config dir exists before opening DB
mkdirSync(CONFIG_DIR, { recursive: true });
this.db = new Database(DB_PATH);
this.db = openDb(DB_PATH);
this.db.exec(SCHEMA);
this.db.exec(SEED_GROUPS);