dataPool() function
A connection pool whose JSON columns can be read.
Signature:
export declare function dataPool(config: PoolConfig, parsers?: TypeParsers): Pool;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
config |
PoolConfig |
Pool configuration, as |
|
parsers |
(Optional) The registry to register in. Defaults to this package's own, which is right whenever there is one copy of |
Returns:
Pool
The pool.
Remarks
Tells node-postgres to leave json and jsonb columns as text, and guards the pool with survivesLostConnections().
**JSON is parsed once, by the ORM.** Its codec parses what it is handed, and node-postgres would have parsed it already. An object survives the second parse; a JSON **string** does not — JSON.parse('Payment') throws, and a column holding "5" quietly comes back as the number 5. json[] and jsonb[] need nothing: the runtime reads every built-in array as raw text itself.
**Arrays of enums are the runtime's own.** An enum's array type is numbered when the enum is created, so node-postgres cannot know it and hands the literal text {EMAIL,SMS} back. Prisma Next up to 8.0.0-rc.11 could not read that, and this pool used to parse it into an array first. From 8.0.0-rc.12 the runtime decodes that text itself and refuses anything already parsed — RUNTIME.DECODE_FAILED, "expected raw text for a Postgres array" — so the text is now left exactly as the driver gives it.
The registry is the one the *runtime* reads, not the one a pool carries: the ORM passes its own types to every query, and that object falls through to pg-types for anything it does not handle itself. A parser set on the pool is therefore never consulted. It follows that the registry is global, and a raw pg query in the same process reads a JSON column as text and has to parse it itself — the trade for the ORM reading it correctly.
Example
const db = postgres<Contract>({
contractJson,
pg: dataPool({ connectionString }),
});
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.