Skip to content

Postgres

@mountsqli/driver-postgres wraps pg. It uses $N parameter style and a connection pool with per-call borrow().

Terminal window
pnpm add @mountsqli/driver-postgres pg
import "@mountsqli/driver-postgres";
import { mountsqli } from "@mountsqli/core";
const db = mountsqli({
driver: "postgres",
url: process.env.DATABASE_URL!,
tables: [users],
});

The dialect compiles plans to $N parameters:

SELECT * FROM "users" WHERE "age" > $1

borrow() returns a self-contained client handle. Each query() takes and releases its own pooled client — borrows never clobber each other (issue 002).

const handle = await driver.borrow();
try {
await handle.query("SELECT 1", []);
} finally {
await handle.release();
}
await db.transaction(async (tx) => {
await tx.from(users).insert({ email: "a@b.c" });
// COMMIT on success, ROLLBACK on throw
});

Commit failures are classified into MountError("QUERY_FAILED") and a rollback is attempted (hardening audit #8).

  • Production server databases.
  • Multi-instance apps (sessions via PgTokenStore).
  • Anything needing real concurrency.
  • Set DATABASE_URL from env, not code.
  • Always release() a borrowed handle (use try/finally).
  • Use PgTokenStore for cross-instance sessions.
  • Assuming ? params (Postgres uses $N).
  • Forgetting to release() a borrowed client → pool exhaustion.