Drizzle ORM
Column Formats
The format each Drizzle column builder gives the inferred model, per database and column mode.
Each column builder in the @mionjs/drizzle-orm-pg-core, -mysql-core and -sqlite-core packages types its column with the matching format from @mionjs/run-types/formats. The column types (Varchar, Integer, Timestamp and so on) give the same data type from the same arguments, so both forms infer the same rows. These rules apply everywhere:
- A column declared with an enum keeps drizzle's exact literal union, with no string format on top.
- A column with no matching format (geometry, vectors, network and binary types, plain booleans and JSON) keeps its plain data type and validates as that primitive.
- PostgreSQL array columns keep the element format:
varchar('codes', {length: 5, array: true})checks every item against the length. Putarraybefore the other modifiers.
PostgreSQL
| Builder | Inferred format |
|---|---|
| varchar (with length) | String with maxLength |
| char (with length) | String with exact length |
| text | String |
| uuid | UUID |
| inet | IP |
| bit | String with exact length |
| integer, serial | Int32 |
| smallint, smallserial | Int16 |
| bigint, bigserial (mode number) | Integer |
| bigint, bigserial (mode bigint) | BigInt64 |
| doublePrecision, real | Float |
| numeric, decimal (mode number) | Float |
| numeric, decimal (string or bigint mode) | plain string or bigint |
| date (default) | StringDate |
| date (mode date) | Date |
| time | StringTime |
| timestamp (default) | Date |
| timestamp (mode string) | StringDateTime |
| boolean, json, jsonb, geometry, vectors, macaddr, cidr, interval, point, line | plain data type |
MySQL
| Builder | Inferred format |
|---|---|
| varchar (length required) | String with maxLength |
| char (with length) | String with exact length |
| text, tinytext, mediumtext, longtext | String |
| int | Int32, or UInt32 when unsigned |
| smallint | Int16, or UInt16 when unsigned |
| tinyint | Int8, or UInt8 when unsigned |
| mediumint | its real signed or unsigned window |
| serial | positive integer |
| year | integer in the 1901 to 2155 window |
| bigint (mode number) | Integer |
| bigint (mode bigint) | BigInt64, or BigUInt64 when unsigned |
| double, float, real | Float |
| decimal (mode number) | Float |
| decimal (string or bigint mode) | plain string or bigint |
| date, datetime, timestamp (default) | Date |
| date (mode string) | StringDate |
| datetime, timestamp (mode string) | StringDateTime |
| time | StringTime |
| mysqlEnum | the exact literal union |
| boolean, json, binary, varbinary | plain data type |
SQLite
| Builder | Inferred format |
|---|---|
| text (with length) | String with maxLength |
| text (mode json) | unknown (use $type for a semantic type) |
| integer, int (default) | Integer |
| integer, int (mode timestamp) | Date |
| integer, int (mode boolean) | plain boolean |
| real | Float |
| numeric (mode number) | Float |
| numeric (string or bigint mode) | plain string or bigint |
| blob (mode bigint) | BigInt |
| blob (buffer or json mode) | plain Buffer, or unknown for json |
Float columns accept whole values like 2.0, and their mock data has fractions.