Postgres
@mountsqli/driver-postgres wraps pg. It uses $N parameter style and a
connection pool with per-call borrow().
Install & use
Section titled “Install & use”pnpm add @mountsqli/driver-postgres pgimport "@mountsqli/driver-postgres";import { mountsqli } from "@mountsqli/core";
const db = mountsqli({ driver: "postgres", url: process.env.DATABASE_URL!, tables: [users],});Parameter style
Section titled “Parameter style”The dialect compiles plans to $N parameters:
SELECT * FROM "users" WHERE "age" > $1Per-call borrow()
Section titled “Per-call borrow()”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();}Transactions
Section titled “Transactions”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).
Best for
Section titled “Best for”- Production server databases.
- Multi-instance apps (sessions via
PgTokenStore). - Anything needing real concurrency.
Best practices
Section titled “Best practices”- Set
DATABASE_URLfrom env, not code. - Always
release()a borrowed handle (use try/finally). - Use
PgTokenStorefor cross-instance sessions.
Common mistakes
Section titled “Common mistakes”- Assuming
?params (Postgres uses$N). - Forgetting to
release()a borrowed client → pool exhaustion.
Related
Section titled “Related”- Drivers → Overview — driver model.
- Sessions —
PgTokenStore.
