FaasJS PostgreSQL
Default Workflow
- Keep table declarations, migrations, queries, and tests aligned.
- Prefer typed
QueryBuilderclauses before raw SQL. - Parameterize raw SQL values and keep trusted boundaries explicit.
- Keep migrations deterministic, lexically sortable, and reversible where possible.
- Pair runtime database assertions with type assertions when query inference is part of the behavior.
- Use explicit transactions and concurrency tests when atomicity or row locking matters.
Load These References
- Declaration merging on
Tablesand concrete row shapes:references/guidelines/pg-table-types.md. QueryBuilder, aliases, raw SQL, update expressions,returning, and edge semantics:references/guidelines/pg-query-builder.md.- Transaction modes, transaction client lifetime, row locks, retry ownership, and concurrency tests:
references/guidelines/pg-transactions-and-locking.md. - Exact
numeric,decimal, andbigintvalues across TypeScript and API boundaries:references/guidelines/pg-numeric-boundaries.md. - Timestamped migrations,
SchemaBuilder,TableBuilder, and schema execution:references/guidelines/pg-schema-and-migrations.md. PgVitestPlugin(), shared migration snapshots, per-file database isolation,DATABASE_URL, andexpectTypeOf(...):references/guidelines/pg-testing.md.
Gotchas
- Treat
Tablesdeclarations as the source of truth for query inference. - Use raw SQL deliberately; move repeated raw SQL back toward shared helpers or builder clauses.
- Keep write queries and transactions guarded by caller scope and expected failure handling; never let a transaction client escape its callback.
- Let
PgVitestPlugin()own the lazy global setup: it migrates one run-scoped snapshot and gives every database-using test file an isolated clone. - When a transaction also calls
enqueueJob, load FaasJS API And Jobs and test rollback of both business data and the job row. DATABASE_URLis required for migration and PG integration test commands.
Validation
- Run
npx faasjs-pg migratewhen schema changes need migration verification andDATABASE_URLis available. - Run focused PG tests with
vp test <pattern>. - Include
expectTypeOf(...)when changing type-sensitive query behavior. - Use overlapping real transactions for lock or concurrency behavior; generated SQL assertions alone are insufficient.