Skip to content

Database type mappings

The inferred row type describes values returned by the typed-sql adapter under the selected typePolicy. Generation and runtime execution must use the same policy object.

PostgreSQL

PostgreSQL typeDefault TypeScript typeRuntime value
smallint, integernumberFinite JavaScript number
bigintbigintNative bigint
numeric, decimalstringExact decimal text
real, double precisionnumberJavaScript number
booleanbooleanJavaScript boolean
text, character, uuidstringJavaScript string
date, timestamp, timestamptzDateJavaScript Date
json, jsonbunknownParsed JSON value
byteaUint8ArrayNode.js Buffer
enumLiteral string unionJavaScript string
supported T[]readonly T[]Recursively decoded array
nullable column`Tnull`

The PostgreSQL adapter installs parsers per query and does not mutate global pg.types. Policy-controlled OIDs use typed-sql codecs; other OIDs delegate to the installed driver parser table.

Policy alternatives:

Policy fieldValuesGuarantee
bigintbigint, string, numbernumber rejects values outside the safe integer range.
numericstring, number, Decimalnumber rejects non-finite values; Decimal requires a converter.
dateDate, stringstring preserves driver text and database precision.
jsonunknown, JsonValue, stringObject modes parse JSON; string preserves text.
enumsstring-union, stringBoth decode strings; only inference changes.

timestamp without time zone follows the Node.js process timezone when represented as Date. JavaScript dates lose PostgreSQL sub-millisecond precision. Choose string when those semantics are not acceptable.

MySQL

MySQL typeDefault TypeScript typeRuntime value
tinyint(1), boolean, boolbooleanStrict 0 or 1 conversion
other integer typesnumberJavaScript number
bigintbigintNative bigint
decimal, numericstringExact decimal text
float, double, realnumberJavaScript number
bitUint8ArrayNode.js Buffer
character, text, time, setstringJavaScript string
binary and blob typesUint8ArrayNode.js Buffer
date, datetime, timestampDateDate converted from lossless text
yearnumberJavaScript number
jsonunknownParsed JSON value
enumLiteral string unionJavaScript string
nullable column`Tnull`

The adapter owns mysql2 settings that affect row shape and decoding. Supplying conflicting options through poolConfig fails before a pool is created.

Policy alternatives:

Policy fieldValuesGuarantee
bigintbigint, string, numbernumber rejects values outside the safe integer range.
decimalstring, number, Decimalnumber may approximate fractions; Decimal requires a converter.
dateDate, stringConversion occurs after mysql2 returns text.
jsonunknown, JsonValue, stringObject modes use parsed JSON; string serializes it.
tinyint1boolean, numberConversion follows field type and length metadata.

Nullability, aggregates, and drift

Nullability is applied after scalar mapping. Outer joins add null to columns from the nullable relation. COUNT follows the dialect's bigint policy, while decimal-producing aggregates follow the numeric or decimal policy.

Generated snapshots include a typePolicyHash. typed-sql drift detects policy changes even when the database catalog remains unchanged.

Released under the MIT License.