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

    Function postgresStore

    • Build a Store backed by Postgres, using real database transactions. The returned transaction(work) checks out one connection, runs work between BEGIN and COMMIT, and rolls back if work throws. Transactions run at Postgres' default READ COMMITTED isolation, with correctness carried by explicit FOR UPDATE row locks rather than a snapshot; a transient abort — deadlock, serialization failure, 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. The trust and checkpoint stores hang off the pool directly, not off a transaction, so their writes are never rolled back.

      Opening fails fast rather than serve a mismatched database: the schema_meta stamp must match this build (unless schema: 'skip'), and the vendored money routines are installed and proven against pinned vectors before any posting trusts their arithmetic. If schemaName is given, a fresh schema with that name is created, loaded with db/postgresql-schema.sql, and used for all queries; close() drops it and ends the pool. The hash dependency defaults to the deterministic SHA-256; the clock defaults to wall-clock time. Pass a fixed clock when reproducible postedAt values matter.

      Parameters

      Returns Promise<Store>

      const store = await postgresStore({
      url: 'postgres://econ:secret@127.0.0.1:5432/economy',
      poolMax: 32, // at least one connection per concurrent submit
      connectionTimeoutMillis: 5_000,
      });
      const economy = createEconomy({ store, ...runtimePorts });
      // ... on shutdown:
      await store.close();

      Storage for the port contracts this engine implements.