Skip to main content
Drizzle ORM provides type-safe column builders for all MySQL data types. Each column type maps to the corresponding MySQL type and TypeScript type.

Numeric Types

int()

MySQL INT type for 32-bit integers.
boolean
default:"false"
Whether the column is unsigned.

Examples


bigint()

MySQL BIGINT type for 64-bit integers. Supports both number and bigint modes.
'number' | 'bigint'
required
  • 'number': Values up to 2^53-1 as JavaScript numbers
  • 'bigint': Full 64-bit range as JavaScript bigint
boolean
default:"false"
Whether the column is unsigned.

Examples


tinyint()

MySQL TINYINT type for small integers (-128 to 127 or 0 to 255 unsigned).

Examples


smallint()

MySQL SMALLINT type for small integers (-32768 to 32767 or 0 to 65535 unsigned).

Examples


mediumint()

MySQL MEDIUMINT type for medium-sized integers.

Examples


serial()

MySQL SERIAL type, which is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.
serial() automatically applies .notNull(), .autoincrement(), and .primaryKey() modifiers.

Examples


decimal()

MySQL DECIMAL type for exact numeric values. Supports string, number, and bigint modes.
'string' | 'number' | 'bigint'
default:"'string'"
How to represent the value in JavaScript.
number
Total number of digits.
number
Number of digits after decimal point.
boolean
default:"false"
Whether the column is unsigned.

Examples


float()

MySQL FLOAT type for single-precision floating-point numbers.

Examples


double()

MySQL DOUBLE type for double-precision floating-point numbers.

Examples


real()

MySQL REAL type, synonym for DOUBLE.

String Types

varchar()

MySQL VARCHAR type for variable-length strings.
number
required
Maximum length of the string (1 to 65,535).
string[]
Array of allowed values for type safety.

Examples


char()

MySQL CHAR type for fixed-length strings.
number
Fixed length of the string (0 to 255). Defaults to 1.

Examples


text()

MySQL TEXT type for long text content (up to 65,535 characters).

Examples


tinytext()

MySQL TINYTEXT type for short text (up to 255 characters).

mediumtext()

MySQL MEDIUMTEXT type for medium-length text (up to 16,777,215 characters).

Examples


longtext()

MySQL LONGTEXT type for very long text (up to 4,294,967,295 characters).

Examples


Binary Types

binary()

MySQL BINARY type for fixed-length binary data.

Examples


varbinary()

MySQL VARBINARY type for variable-length binary data.

Examples


Date and Time Types

date()

MySQL DATE type for dates without time.
'date' | 'string'
default:"'date'"
  • 'date': JavaScript Date object
  • 'string': ISO date string (YYYY-MM-DD)

Examples


datetime()

MySQL DATETIME type for date and time.
'date' | 'string'
default:"'date'"
How to represent the value in JavaScript.
0 | 1 | 2 | 3 | 4 | 5 | 6
Fractional seconds precision (0-6 digits).

Examples


timestamp()

MySQL TIMESTAMP type for Unix timestamps.
'date' | 'string'
default:"'date'"
How to represent the value in JavaScript.
0 | 1 | 2 | 3 | 4 | 5 | 6
Fractional seconds precision.
TIMESTAMP has a range from ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC.

Examples


time()

MySQL TIME type for time of day.

Examples


year()

MySQL YEAR type for year values.

Examples


Boolean Type

boolean()

MySQL BOOLEAN type (alias for TINYINT(1)).

Examples


JSON Type

json()

MySQL JSON type for storing JSON data.
The JSON column automatically serializes/deserializes JavaScript objects.

Examples


Enum Type

mysqlEnum()

MySQL ENUM type for predefined string values.
string[]
required
Array of allowed enum values (at least one value required).

Examples


Custom Types

customType()

Define custom column types with custom serialization/deserialization logic.
function
required
Function that returns the MySQL column type as a string.
function
Transform value before sending to database.
function
Transform value after reading from database.

Examples


Column Modifiers

All column types support these common modifiers:

notNull()

Makes the column required (NOT NULL constraint).

default()

Sets a default value for the column.

defaultNow()

Sets default to current timestamp (for date/time columns).

onUpdateNow()

Automatically updates to current timestamp on row update (for timestamp columns).

primaryKey()

Marks the column as primary key.

autoincrement()

Enables auto-increment for integer columns.

unique()

Adds a unique constraint to the column.

references()

Defines a foreign key reference to another table.

$type()

Overrides the TypeScript type for the column.