# @imqueue/pg-prisma 2.0.0 · API reference

Source: https://imqueue.org/api/pg-prisma/latest/
Published: 2026-08-28
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-prisma 2.0.0 — generated reference, not hand-written

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 |
| --- | --- |
| [accessScope(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.accessscope/) | Build the middleware restricting statements to the records a caller may see. |
| [audit(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.audit/) | Build the middleware recording every write to the tables it is given. |
| [dataLayer(options)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayer_1/) | Build the whole data layer from an emitted contract, in one call. |
| [dataPool(config, parsers)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datapool/) | A connection pool whose arrays of enums and JSON columns can be read. |
| [deriveDataLayer(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.derivedatalayer/) | Derive the data-layer config from an emitted contract. |
| [emitAll(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitall/) | Emit every generated file for a contract. |
| [emitEnums(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitenums/) | Emit the enum constants for a contract. |
| [emitImports(names, map)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitimports/) | Emit the import statements for the runtimes a file uses. |
| [emitModels(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitmodels/) |  |
| [emitRpcTypes(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitrpctypes/) | Emit the RPC query, input and argument classes for a contract. |
| [hasDatabaseDefault(models, columnsOf)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.hasdatabasedefault/) | Whether the database fills a column in when an insert leaves it out. |
| [installArchiving(options)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.installarchiving/) | Install the row-archiving machinery: a mirror `archive` schema, its settings table, the sweep function, and — best effort — a pg\_cron schedule to run it. |
| [installChangeTriggers(client, input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.installchangetriggers/) | Install Postgres triggers that `NOTIFY` on every row change in the given tables. |
| [isoDates(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.isodates/) | Read database timestamps back as canonical ISO 8601 instants. |
| [isSqlLogSuppressed()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.issqllogsuppressed/) | Whether SQL logging is currently suppressed. |
| [join(parts, separator)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.join/) | Several fragments, one after another. |
| [namespaceOf(contract, namespace, omit)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.namespaceof/) |  |
| [parseImportMap(spec)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.parseimportmap/) | Read an import map from its generator-option spelling. |
| [prettifySql(sql)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.prettifysql/) | Format a one-line SQL string so it is readable in a log. |
| [queryLog(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.querylog/) | Build the middleware that logs each statement and how long it took. |
| [quoted(value)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.quoted/) | Quote a `@property` type string. |
| [raw(text)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.raw/) | Text spliced in as written, binding nothing. |
| [repositoriesFor(db, input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.repositoriesfor/) | Build the CRUD façade the RPC surface delegates to. |
| [scopePredicate(qualifier, levels, resolvers)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.scopepredicate/) | Compose the scope predicate for one table, or null when nothing constrains it. |
| [silently(fn)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.silently/) | Run `fn` with SQL logging suppressed. |
| [sql(strings, values)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sql/) | SQL as a tagged template, with everything interpolated bound. |
| [sqlRunner(pool)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlrunner_1/) | A `query` and a `transaction` that agree about which connection to use. |
| [stamp(input)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.stamp/) | Build the middleware that stamps authorship and turns deletes into stamps. |
| [toOrdering(orderBy)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.toordering/) | Turn a wire ordering into the callbacks `.orderBy()` takes. |
| [toPredicate(relations, model, where)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.topredicate/) | Turn a wire filter into the predicate callback `.where()` takes. |
| [toProjection(relations, model, select)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.toprojection/) | Split a wire projection into its scalar and relation halves. |
| [toQuery(fragment)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.toquery/) | A fragment as the pair `query` takes. |
| [transactionFor(db, options)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.transactionfor/) | Repositories bound to a transaction. |
| [typeOf(field, enums, listEnum)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.typeof/) | The TypeScript spelling of a field, and the `@property` type string. |
| [withoutChangeNotify(client, fn, setting)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.withoutchangenotify/) | Run `fn` in a transaction whose row changes notify nobody. |
| [withTransaction(pool, fn)](https://imqueue.org/api/pg-prisma/latest/pg-prisma.withtransaction/) | Run `fn` inside a transaction on one connection. |


## Interfaces


| Interface | Description |
| --- | --- |
| [AccessScopeOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.accessscopeoptions/) | Everything [accessScope()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.accessscope/) needs to build its middleware. |
| [ArchivableModel](https://imqueue.org/api/pg-prisma/latest/pg-prisma.archivablemodel/) | One watched table to seed into the archive settings table. |
| [AuditColumns](https://imqueue.org/api/pg-prisma/latest/pg-prisma.auditcolumns/) | Column names within the audit table. |
| [AuditConfig](https://imqueue.org/api/pg-prisma/latest/pg-prisma.auditconfig/) | Where the trail goes and what its columns are called. |
| [AuditOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.auditoptions/) | Everything [audit()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.audit/) needs to build its middleware. |
| [BulkCount](https://imqueue.org/api/pg-prisma/latest/pg-prisma.bulkcount/) | How many rows a bulk write affected. |
| [ChangeTriggerConfig](https://imqueue.org/api/pg-prisma/latest/pg-prisma.changetriggerconfig/) | Which tables notify, and under which Postgres object names. |
| [ContractJson](https://imqueue.org/api/pg-prisma/latest/pg-prisma.contractjson/) | The slice of an emitted `contract.json` this derivation reads. |
| [DataLayer](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayer/) | What [dataLayer()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayer_1/) hands back. |
| [DataLayerAudit](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayeraudit/) | The audit half of [DataLayerOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayeroptions/), omitted to record nothing. |
| [DataLayerOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayeroptions/) | Everything [dataLayer()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayer_1/) needs. |
| [DerivedDataLayer](https://imqueue.org/api/pg-prisma/latest/pg-prisma.deriveddatalayer/) | The config the middlewares consume, keyed by physical table. |
| [DeriveFields](https://imqueue.org/api/pg-prisma/latest/pg-prisma.derivefields/) | Field names to look for, where they are not the defaults. |
| [DeriveOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.deriveoptions/) | Everything [deriveDataLayer()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.derivedatalayer/) needs. |
| [EmitAllOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitalloptions/) | Everything [emitAll()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitall/) needs. |
| [EmitContract](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitcontract/) | The slice of an emitted `contract.json` the emitter reads. |
| [EmitModelsOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitmodelsoptions/) | Everything [emitModels()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitmodels/) needs. |
| [EmitRpcOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitrpcoptions/) | Everything [emitRpcTypes()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.emitrpctypes/) needs. |
| [EnumDef](https://imqueue.org/api/pg-prisma/latest/pg-prisma.enumdef/) |  |
| [Field](https://imqueue.org/api/pg-prisma/latest/pg-prisma.field/) |  |
| [FilterOps](https://imqueue.org/api/pg-prisma/latest/pg-prisma.filterops/) | The comparison operators a caller may send for one field. |
| [InstallArchiveOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.installarchiveoptions/) | Everything [installArchiving()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.installarchiving/) needs. |
| [IsoDateOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.isodateoptions/) | Everything [isoDates()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.isodates/) needs. |
| [Model](https://imqueue.org/api/pg-prisma/latest/pg-prisma.model/) |  |
| [Page](https://imqueue.org/api/pg-prisma/latest/pg-prisma.page/) | A page of entities, and the total when one was asked for. |
| [PageOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.pageoptions/) | Paging and whether to count. |
| [Projection](https://imqueue.org/api/pg-prisma/latest/pg-prisma.projection/) | A projection split into what `select` takes and what `include` takes. |
| [QueryLogger](https://imqueue.org/api/pg-prisma/latest/pg-prisma.querylogger/) | Where a query log line goes. |
| [QueryLogOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.querylogoptions/) | Everything [queryLog()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.querylog/) needs. |
| [Relation](https://imqueue.org/api/pg-prisma/latest/pg-prisma.relation/) |  |
| [RelationInfo](https://imqueue.org/api/pg-prisma/latest/pg-prisma.relationinfo/) | One relation, as the query translator needs it. |
| [Repository](https://imqueue.org/api/pg-prisma/latest/pg-prisma.repository/) | The CRUD surface exposed for one model. |
| [RepositoryOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.repositoryoptions/) | Everything [repositoriesFor()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.repositoriesfor/) needs. |
| [RuntimeModule](https://imqueue.org/api/pg-prisma/latest/pg-prisma.runtimemodule/) | A module the generated code imports from, and what it takes from it. |
| [SqlConnection](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlconnection/) | A connection held for the length of a transaction. |
| [SqlExecutor](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlexecutor/) | The minimum this package needs of a Postgres connection. |
| [SqlFragment](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlfragment/) | A statement and the values bound into it. |
| [SqlPool](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlpool/) | An executor that can hand out a dedicated connection. |
| [SqlRunner](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlrunner/) | What [sqlRunner()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.sqlrunner_1/) returns. |
| [StampColumns](https://imqueue.org/api/pg-prisma/latest/pg-prisma.stampcolumns/) | Columns a model is stamped with, by physical column name. |
| [StampOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.stampoptions/) | Everything [stamp()](https://imqueue.org/api/pg-prisma/latest/pg-prisma.stamp/) needs to build its middleware. |
| [Transactional](https://imqueue.org/api/pg-prisma/latest/pg-prisma.transactional/) | A client that can run work inside one transaction. |
| [TypeParsers](https://imqueue.org/api/pg-prisma/latest/pg-prisma.typeparsers/) | What `pg-types` offers, of which only these two are wanted. |


## Variables


| Variable | Description |
| --- | --- |
| [AuditAction](https://imqueue.org/api/pg-prisma/latest/pg-prisma.auditaction/) | The three write actions the trail records. |
| [CHANGE\_NOTIFY\_CHANNEL](https://imqueue.org/api/pg-prisma/latest/pg-prisma.change_notify_channel/) | Default Postgres NOTIFY channel the change triggers emit on. |
| [CHANGE\_NOTIFY\_FUNCTION\_NAME](https://imqueue.org/api/pg-prisma/latest/pg-prisma.change_notify_function_name/) | Default name of the trigger's plpgsql notify function. |
| [CHANGE\_NOTIFY\_SUPPRESS\_SETTING](https://imqueue.org/api/pg-prisma/latest/pg-prisma.change_notify_suppress_setting/) | Setting the trigger reads to decide whether to stay quiet. |
| [CHANGE\_NOTIFY\_TRIGGER\_NAME](https://imqueue.org/api/pg-prisma/latest/pg-prisma.change_notify_trigger_name/) | Default name of the per-table change trigger. |
| [EMPTY](https://imqueue.org/api/pg-prisma/latest/pg-prisma.empty/) | A fragment that contributes nothing, for the empty case. |
| [RUNTIME](https://imqueue.org/api/pg-prisma/latest/pg-prisma.runtime/) | Where each runtime lives by default. |
| [TIMESTAMP\_CODECS](https://imqueue.org/api/pg-prisma/latest/pg-prisma.timestamp_codecs/) | Codecs whose values arrive as Postgres' own timestamp text. |


## Type Aliases


| Type Alias | Description |
| --- | --- |
| [AccessScopeResolver](https://imqueue.org/api/pg-prisma/latest/pg-prisma.accessscoperesolver/) | Resolves the current request's value for one access level: - `undefined` — the level does not constrain this request (skip it), - `null` — active but valueless, so deny (match nothing), - a string — match rows where a scope column equals it, - an array — match rows where a scope column is `IN` it (empty denies). |
| [ArchiveClient](https://imqueue.org/api/pg-prisma/latest/pg-prisma.archiveclient/) | The raw-SQL surface this installer needs. |
| [Direction](https://imqueue.org/api/pg-prisma/latest/pg-prisma.direction/) | Sort direction. |
| [EnumNames](https://imqueue.org/api/pg-prisma/latest/pg-prisma.enumnames/) | Member names per enum, where the label is not the name. |
| [Fields](https://imqueue.org/api/pg-prisma/latest/pg-prisma.fields/) | The object a predicate callback is handed. |
| [ImportMap](https://imqueue.org/api/pg-prisma/latest/pg-prisma.importmap/) | Original specifier to the specifier to emit in its place. |
| [OrderBy](https://imqueue.org/api/pg-prisma/latest/pg-prisma.orderby/) | An ordering as it arrives over the wire: `{ createdAt: 'desc' }`. |
| [RawClient](https://imqueue.org/api/pg-prisma/latest/pg-prisma.rawclient/) | A [RawExecutor](https://imqueue.org/api/pg-prisma/latest/pg-prisma.rawexecutor/) that can also open a transaction. |
| [RawExecutor](https://imqueue.org/api/pg-prisma/latest/pg-prisma.rawexecutor/) | The raw-SQL surface used to install triggers. A `pg.Pool` satisfies it. |
| [RelationMap](https://imqueue.org/api/pg-prisma/latest/pg-prisma.relationmap/) | Relations per model, by field name. |
| [RowOf](https://imqueue.org/api/pg-prisma/latest/pg-prisma.rowof/) | A model as a row that was read whole. |
| [RuntimeName](https://imqueue.org/api/pg-prisma/latest/pg-prisma.runtimename/) | A runtime the generated code can import from. |
| [ScopeTables](https://imqueue.org/api/pg-prisma/latest/pg-prisma.scopetables/) | Scope columns per physical table, per access level. |
| [Select](https://imqueue.org/api/pg-prisma/latest/pg-prisma.select/) | A projection as it arrives over the wire: `{ id: true, user: { … } }`. |
| [StampTables](https://imqueue.org/api/pg-prisma/latest/pg-prisma.stamptables/) | Stamp columns per physical table. |
| [StorageTables](https://imqueue.org/api/pg-prisma/latest/pg-prisma.storagetables/) | Storage columns per physical table. |
| [ValidationRules](https://imqueue.org/api/pg-prisma/latest/pg-prisma.validationrules/) | Zod suffixes per model per field, as the schema's `@validate` declared. |
| [Where](https://imqueue.org/api/pg-prisma/latest/pg-prisma.where/) | A filter as it arrives over the wire. |

