dbd209ac2b
server/dbx.js selects a backend by DB_BACKEND (default sqlite; pg added at cutover).
server/db/sqlite.js wraps the synchronous node:sqlite instance in the async
interface repos will call — prepare(sql).{get,all,run}, exec(sql), tx(fn), init().
Results come back as resolved Promises so identical repo code runs on synchronous
SQLite (dev/test) and asynchronous Postgres (prod).
tx() gives multi-statement atomicity that stays correct on both engines (sqlite is
single-connection; the pg backend will run it on one pooled client) — needed for the
account-merge transaction in repos.
Verified: get/all/run/tx all work end-to-end; confirmed no code reads
.changes/.lastInsertRowid, so the repo conversion is purely sync->Promise. Unwired —
nothing requires dbx.js yet; prod path untouched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7 lines
511 B
JavaScript
7 lines
511 B
JavaScript
// Async DB adapter facade. The backend is chosen by DB_BACKEND (default 'sqlite'); 'pg' is added at
|
|
// cutover. Every backend implements the same async interface — prepare(sql).{get,all,run}, exec(sql),
|
|
// tx(fn), init() — so repos and app code are engine-agnostic. Swapping engines is one backend file, no
|
|
// repo changes. (This is the same "never hardwire the engine" principle we'll apply to the pub/sub layer.)
|
|
const name = process.env.DB_BACKEND || 'sqlite';
|
|
module.exports = require('./db/' + name);
|