isoDates() function
Read database timestamps back as canonical ISO 8601 instants.
Signature:
export declare function isoDates(input: IsoDateOptions): SqlMiddleware;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
input |
Returns:
SqlMiddleware
Middleware converting those columns on every row read.
Remarks
Postgres prints a timestamp as 2026-08-14 09:30:00.123+00 — a space where ISO 8601 puts a T, +00 where it puts Z, and a fraction stripped of its trailing zeros, so 09:30:00.500 comes back as 09:30:00.5 and a whole second as no fraction at all. Nothing downstream accepts that: the GraphQL DateTime scalar rejects it outright, and so does z.iso.datetime(). This restores the one spelling every boundary agrees on, which is what Prisma 7's scalars = "DateTime:string" used to produce.
A column that carries no zone is read as UTC rather than as a wall clock. Left to new Date, such a value is parsed as **local** time, so on a host that is not UTC every instant read from the database is silently shifted and an expiry compares against the wrong moment — which is why the columns are timestamptz and this is only the fallback for one that is not.
Sub-millisecond precision does not survive, because a JavaScript instant has none to survive into.
Writes need nothing: Postgres parses an ISO 8601 string on its own, so a value handed back unchanged can be sent straight back.
Both the column name and the value's shape have to match, so a text column that happens to hold something timestamp-like is left alone.
Example
const middleware = [isoDates({ columns: derived.dates })];
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.