@pwngh/economy-lab
    Preparing search index...

    Function mysqlStore

    • Build the full MySQL-backed store on a connection pool the caller creates and owns — the mysql2 pool from createMysqlPool, or the pipelining mariadb pool from @pwngh/economy-lab/engines/mysql-mariadb; both fill the same MysqlPool seam and run the same SQL against the same schema.

      transaction(work) borrows one connection, wraps work in START TRANSACTION ... COMMIT, and rolls back if work throws. Money transactions run at READ COMMITTED (set once per pooled connection); correctness comes from explicit FOR UPDATE row locks plus a GET_LOCK named lock per account. A transient InnoDB abort — deadlock, lock-wait timeout, named-lock deadlock, or a stale-head chain fork — committed nothing, so the whole unit of work is re-run in a fresh connection and transaction and callers never see it as an error. Every posting appends to a per-account hash chain, and the schema's triggers enforce conservation and chain continuity on every write. On the way out of a transaction every named lock the connection acquired is released, so a returned connection carries no leftover locks. Anything outside a transaction (plain reads/writes, plus the trust and checkpoint stores) runs directly on the pool and commits on its own.

      The hash service defaults to the deterministic web-standard SHA-256; the clock defaults to wall-clock time. Pass a fixed clock when reproducible postedAt values matter. The velocity window defaults to one hour.

      Parameters

      • deps: {
            clock?: Clock;
            digest?: Digest;
            logger?: Logger;
            meter?: Meter;
            pool: MysqlPool;
            schema?: "assert" | "skip";
            velocityWindowMs?: number;
        }
        • Optionalclock?: Clock

          Time source for postedAt and window math; defaults to wall-clock time.

        • Optionaldigest?: Digest

          Hash service for chain links; defaults to the deterministic web-standard SHA-256.

        • Optionallogger?: Logger
        • Optionalmeter?: Meter

          Optional runtime ports for the engine's own telemetry (transient-retry pressure). The composition passes the runtime meter and logger; unset emits nothing.

        • pool: MysqlPool
        • Optionalschema?: "assert" | "skip"

          Open-path schema policy: 'assert' verifies the schema_meta stamp before the first operation of any kind; 'skip' (the default here) is for the staged open that already asserted on the pool. Migration is applyMysqlSchema or an external migrate job — never an open option.

        • OptionalvelocityWindowMs?: number

          Rolling window (ms) the trust store applies when summing a subject's recent spend for the velocity check. Defaults to one hour; the composition passes config.velocityWindowMs.

      Returns Store

      Storage for the store and outbox/inbox ports this backs.