Drizzle ORM

Column Mapping

How types are mapped to database columns when using mion Drizzle ORM package.

The @mionkit/drizzle package automatically maps TypeScript types to appropriate Drizzle ORM column definitions. This mapping is database-aware, using native column types where available (e.g., PostgreSQL's uuid() and inet()) and falling back to compatible alternatives for databases with fewer native types (e.g., SQLite uses text() for most string formats).

Type formats from @mionkit/type-formats provide additional semantic information that enables more precise column mapping. For example, NumInteger maps to an integer column rather than a floating-point column, and StrEmail uses the appropriate varchar length for email addresses.

Primitive Types

TypeScript TypePostgreSQLMySQLSQLite
stringvarchar(255)varchar(255)text()
numberdoublePrecision()double()real()
booleanboolean()boolean()integer({mode: 'boolean'})
bigintbigint({mode: 'bigint'})bigint({mode: 'bigint'})blob({mode: 'bigint'})
Datetimestamp()timestamp()integer({mode: 'timestamp'})

String Format Types

Format TypePostgreSQLMySQLSQLite
StrUUID / StrUUIDv7uuid()varchar(36)text()
StrEmailvarchar(254)varchar(254)text()
StrURLvarchar(2048)varchar(2048)text()
StrDomainvarchar(253)varchar(253)text()
StrIP / StrIPv4 / StrIPv6inet()varchar(45)text()
StrDateTimetimestamp()datetime()text()
StrDatedate()date()text()
StrTimetime()time()text()
StrFormat (with maxLength)varchar(maxLength * buffer)varchar(maxLength * buffer)text()

Well-known formats like StrEmail, StrURL, and StrDomain use their standard maximum lengths without any buffer applied.

Number Format Types

All number formats with the integer: true parameter map to integer columns, while formats with float: true or no integer constraint map to floating-point columns.

Format TypeDescriptionPostgreSQLMySQLSQLite
NumIntegerGeneric integerinteger()int()integer()
NumFloatGeneric floatdoublePrecision()double()real()
NumPositiveNumber >= 0doublePrecision()double()real()
NumNegativeNumber <= 0doublePrecision()double()real()
NumPositiveIntInteger >= 0integer()int()integer()
NumNegativeIntInteger <= 0integer()int()integer()
NumInt88-bit signed (-128 to 127)integer()int()integer()
NumInt1616-bit signed (-32768 to 32767)integer()int()integer()
NumInt3232-bit signedinteger()int()integer()
NumUInt88-bit unsigned (0 to 255)integer()int()integer()
NumUInt1616-bit unsigned (0 to 65535)integer()int()integer()
NumUInt3232-bit unsigned (0 to 4294967295)integer()int()integer()
While the database column type is the same for all integer formats, the type constraints (min/max values) are still validated at runtime by mion's type system.

BigInt Format Types

Format TypePostgreSQLMySQLSQLite
BigNumFormatbigint({mode: 'bigint'})bigint({mode: 'bigint'})blob({mode: 'bigint'})

Complex Types

TypeScript TypePostgreSQLMySQLSQLite
T[] (array)jsonb()json()text({mode: 'json'})
{...} (object)jsonb()json()text({mode: 'json'})