pg-prisma package
Prisma Next (8.x) and Postgres building blocks for @imqueue services.
Two kinds of thing live here, and they are used at different times.
Query middlewares rewrite the statement before it is lowered to SQL: stamp turns deletes into deletedAt stamps, hides stamped rows and records who created, updated or deleted a row; accessScope narrows every read to the records the caller is allowed to see; and audit writes a trail of every write to a table you nominate. dataLayer builds all three from an emitted contract in one call and is the entry point for the ordinary case — the individual factories are there to compose something it does not cover.
Installers and tools run once at startup or by hand rather than per query: installArchiving moves aged rows into a mirror archive schema on a pg_cron schedule, installChangeTriggers makes Postgres NOTIFY on every row change, and prettifySql/silently/isSqlLogSuppressed are query-logging helpers.
The per-model configuration is **derived from contract.json** by deriveDataLayer rather than generated: Prisma Next has no custom-generator protocol and needs none, since the contract already names every model, field and physical column. Nothing is written to disk and nothing can go stale against the schema. Access levels are the one thing that cannot be derived — Prisma Next has no schema annotation to carry them — so they are declared where dataLayer is called.
The middlewares commute: stamp merges what were two order-dependent Prisma 7 extensions, so there is no ordering left for a caller to get wrong.
Functions
|
Function |
Description |
|---|---|
|
Build the middleware restricting statements to the records a caller may see. | |
|
Build the middleware recording every write to the tables it is given. | |
|
Build the whole data layer from an emitted contract, in one call. | |
|
A connection pool whose arrays of enums and JSON columns can be read. | |
|
Derive the data-layer config from an emitted contract. | |
|
Emit every generated file for a contract. | |
|
Emit the enum constants for a contract. | |
|
Emit the import statements for the runtimes a file uses. | |
|
Emit the RPC query, input and argument classes for a contract. | |
|
Whether the database fills a column in when an insert leaves it out. | |
|
Install the row-archiving machinery: a mirror | |
|
Install Postgres triggers that | |
|
Read database timestamps back as canonical ISO 8601 instants. | |
|
Whether SQL logging is currently suppressed. | |
|
Several fragments, one after another. | |
|
Read an import map from its generator-option spelling. | |
|
Format a one-line SQL string so it is readable in a log. | |
|
Build the middleware that logs each statement and how long it took. | |
|
Quote a | |
|
Text spliced in as written, binding nothing. | |
|
Build the CRUD façade the RPC surface delegates to. | |
|
Compose the scope predicate for one table, or null when nothing constrains it. | |
|
Run | |
|
SQL as a tagged template, with everything interpolated bound. | |
|
A | |
|
Build the middleware that stamps authorship and turns deletes into stamps. | |
|
Turn a wire ordering into the callbacks | |
|
Turn a wire filter into the predicate callback | |
|
Split a wire projection into its scalar and relation halves. | |
|
A fragment as the pair | |
|
Repositories bound to a transaction. | |
|
The TypeScript spelling of a field, and the | |
|
Run | |
|
Run |
Interfaces
|
Interface |
Description |
|---|---|
|
Everything accessScope() needs to build its middleware. | |
|
One watched table to seed into the archive settings table. | |
|
Column names within the audit table. | |
|
Where the trail goes and what its columns are called. | |
|
Everything audit() needs to build its middleware. | |
|
How many rows a bulk write affected. | |
|
Which tables notify, and under which Postgres object names. | |
|
The slice of an emitted | |
|
What dataLayer() hands back. | |
|
The audit half of DataLayerOptions, omitted to record nothing. | |
|
Everything dataLayer() needs. | |
|
The config the middlewares consume, keyed by physical table. | |
|
Field names to look for, where they are not the defaults. | |
|
Everything deriveDataLayer() needs. | |
|
Everything emitAll() needs. | |
|
The slice of an emitted | |
|
Everything emitModels() needs. | |
|
Everything emitRpcTypes() needs. | |
|
The comparison operators a caller may send for one field. | |
|
Everything installArchiving() needs. | |
|
Everything isoDates() needs. | |
|
A page of entities, and the total when one was asked for. | |
|
Paging and whether to count. | |
|
A projection split into what | |
|
Where a query log line goes. | |
|
Everything queryLog() needs. | |
|
One relation, as the query translator needs it. | |
|
The CRUD surface exposed for one model. | |
|
Everything repositoriesFor() needs. | |
|
A module the generated code imports from, and what it takes from it. | |
|
A connection held for the length of a transaction. | |
|
The minimum this package needs of a Postgres connection. | |
|
A statement and the values bound into it. | |
|
An executor that can hand out a dedicated connection. | |
|
What sqlRunner() returns. | |
|
Columns a model is stamped with, by physical column name. | |
|
Everything stamp() needs to build its middleware. | |
|
A client that can run work inside one transaction. | |
|
What |
Variables
|
Variable |
Description |
|---|---|
|
The three write actions the trail records. | |
|
Default Postgres NOTIFY channel the change triggers emit on. | |
|
Default name of the trigger's plpgsql notify function. | |
|
Setting the trigger reads to decide whether to stay quiet. | |
|
Default name of the per-table change trigger. | |
|
A fragment that contributes nothing, for the empty case. | |
|
Where each runtime lives by default. | |
|
Codecs whose values arrive as Postgres' own timestamp text. |
Type Aliases
|
Type Alias |
Description |
|---|---|
|
Resolves the current request's value for one access level: - | |
|
The raw-SQL surface this installer needs. | |
|
Sort direction. | |
|
Member names per enum, where the label is not the name. | |
|
The object a predicate callback is handed. | |
|
Original specifier to the specifier to emit in its place. | |
|
An ordering as it arrives over the wire: | |
|
A RawExecutor that can also open a transaction. | |
|
The raw-SQL surface used to install triggers. A | |
|
Relations per model, by field name. | |
|
A model as a row that was read whole. | |
|
A runtime the generated code can import from. | |
|
Scope columns per physical table, per access level. | |
|
A projection as it arrives over the wire: | |
|
Stamp columns per physical table. | |
|
Storage columns per physical table. | |
|
Zod suffixes per model per field, as the schema's | |
|
A filter as it arrives over the wire. |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.