Number of writes currently buffered in the collector (0 when disabled).
Initialise the driver & collector from config.
Engine mode + collector settings.
ConfigurationError if the config is missing required fields, or if the engine's
optional peer dependency (better-sqlite3 for local, pg for cloud) isn't installed.
Calling this on an already connected DAL replaces the engine instead of leaking it => the
previous collector is flushed & stopped and the previous driver closed (same work as
DAL.close), with a console.warn so it doesn't happen unnoticed. Without that the old
pg pool, flush timer & signal listeners stayed alive forever, and anything still buffered on
the old collector was never written by anybody.
fragile, the order matters => the new engine is fully built (peer dep imported, driver
constructed & its own config validated) before the old one is torn down, so a connect()
that throws — bad config, a missing better-sqlite3/pg, a bad busyTimeout — leaves the
connection you already had fully intact. Only once the replacement exists do we flush & close
the old one and swap it in.
Start a fluent chain on the given schema.
Maps to ./data/databases/<name>.db in local mode, or the Postgres logical schema
<name> in cloud mode.
Schema name. Must match ^[a-zA-Z0-9_-]+$.
NotConnectedError if called before connect().
Flush any pending writes & close all connections. Call on graceful shutdown.
Swap this DAL onto the other engine from code => same migration as
npm run db:engine-swap, no terminal involved.
Pending writes are flushed & the current handles closed first (deleting a .db file out
from under an open connection is asking for trouble), then the data moves, then the DAL
reconnects on the target engine reusing the same collector settings.
Closing first is also what lets an upward swap clean up the local files => a directory a DAL in this process still has open counts as un quiesced and is never deleted from, because a write sitting in its collector buffer is invisible to a migration reading the file.
Anything you don't pass is inherited from connect() => dataDir in local mode,
connectionString in cloud mode, falling back to DATABASE_URL. Missing schemas,
tables & directories on the target side are created.
Direction plus any overrides. See DalSwapOptions.
NotConnectedError if called before connect().
ConfigurationError if no Postgres connection string can be resolved.
The DAL instance. Create one with createDAL, then
connect()before use. A single instance is meant to be shared across your whole app.