Skip to main content

Numeric Types

integer()

PostgreSQL INTEGER type for whole numbers.
TypeScript type: number SQL type: INTEGER

serial()

Auto-incrementing integer column.
TypeScript type: number SQL type: SERIAL (equivalent to INTEGER with DEFAULT nextval('sequence')) Note: Automatically has .notNull() and .default() applied.

bigint()

PostgreSQL BIGINT type for large integers.
'number' | 'bigint'
required
  • 'number': Use JavaScript number (safe up to 2^53)
  • 'bigint': Use JavaScript bigint for larger values
TypeScript type: number or bigint (based on mode) SQL type: BIGINT

bigserial()

Auto-incrementing bigint column.
'number' | 'bigint'
required
Determines whether to use JavaScript number or bigint
SQL type: BIGSERIAL

smallint()

PostgreSQL SMALLINT type for small integers (-32,768 to 32,767).
TypeScript type: number SQL type: SMALLINT

smallserial()

Auto-incrementing smallint column.
SQL type: SMALLSERIAL

numeric()

PostgreSQL NUMERIC/DECIMAL type for exact decimal values.
number
Total number of digits
number
Number of digits after decimal point
'string' | 'number' | 'bigint'
  • 'string' (default): Returns string for exact precision
  • 'number': Converts to JavaScript number
  • 'bigint': Converts to JavaScript bigint
TypeScript type: string, number, or bigint (based on mode) SQL type: NUMERIC(precision, scale) Alias: decimal() - same as numeric()

real()

PostgreSQL REAL type for floating-point numbers (single precision).
TypeScript type: number SQL type: REAL

doublePrecision()

PostgreSQL DOUBLE PRECISION type for floating-point numbers.
TypeScript type: number SQL type: DOUBLE PRECISION

String Types

varchar()

PostgreSQL VARCHAR type for variable-length strings.
number
Maximum string length. If omitted, creates VARCHAR without length limit.
readonly string[]
TypeScript enum values for type safety
TypeScript type: string SQL type: VARCHAR or VARCHAR(length)

char()

PostgreSQL CHAR type for fixed-length strings.
number
Fixed string length
TypeScript type: string SQL type: CHAR(length)

text()

PostgreSQL TEXT type for unlimited-length strings.
readonly string[]
TypeScript enum values for type safety
TypeScript type: string SQL type: TEXT

Date and Time Types

timestamp()

PostgreSQL TIMESTAMP type for date and time.
'date' | 'string'
  • 'date' (default): Use JavaScript Date objects
  • 'string': Keep as ISO 8601 string
boolean
If true, creates TIMESTAMP WITH TIME ZONE. Default: false
0 | 1 | 2 | 3 | 4 | 5 | 6
Fractional seconds precision (0-6 digits)
TypeScript type: Date or string (based on mode) SQL type: TIMESTAMP or TIMESTAMP WITH TIME ZONE

date()

PostgreSQL DATE type for dates without time.
'date' | 'string'
  • 'string' (default): ISO date string format
  • 'date': JavaScript Date object
TypeScript type: string or Date (based on mode) SQL type: DATE

time()

PostgreSQL TIME type for time without date.
boolean
If true, creates TIME WITH TIME ZONE
0 | 1 | 2 | 3 | 4 | 5 | 6
Fractional seconds precision
TypeScript type: string SQL type: TIME or TIME WITH TIME ZONE

interval()

PostgreSQL INTERVAL type for time intervals.
string
Interval fields specification (e.g., ‘day’, ‘hour to second’)
0 | 1 | 2 | 3 | 4 | 5 | 6
Fractional seconds precision
TypeScript type: string SQL type: INTERVAL

Boolean Type

boolean()

PostgreSQL BOOLEAN type.
TypeScript type: boolean SQL type: BOOLEAN

JSON Types

json()

PostgreSQL JSON type for JSON data.
TypeScript type: unknown (use generic type parameter for type safety) SQL type: JSON

jsonb()

PostgreSQL JSONB type for binary JSON (more efficient, supports indexing).
TypeScript type: unknown (use generic type parameter for type safety) SQL type: JSONB Note: JSONB is generally preferred over JSON for better performance and indexing support.

UUID Type

uuid()

PostgreSQL UUID type.
TypeScript type: string SQL type: UUID Methods:
  • .defaultRandom(): Sets default to gen_random_uuid()

Network Types

inet()

PostgreSQL INET type for IPv4 or IPv6 addresses.
TypeScript type: string SQL type: INET

cidr()

PostgreSQL CIDR type for network addresses.
TypeScript type: string SQL type: CIDR

macaddr()

PostgreSQL MACADDR type for MAC addresses.
TypeScript type: string SQL type: MACADDR

macaddr8()

PostgreSQL MACADDR8 type for MAC addresses (EUI-64 format).
TypeScript type: string SQL type: MACADDR8

Geometric Types

point()

PostgreSQL POINT type for geometric points.
TypeScript type: Configurable via generic SQL type: POINT

line()

PostgreSQL LINE type.
SQL type: LINE

Enum Types

pgEnum()

Defines a PostgreSQL enum type.
string
required
Enum type name in database
readonly string[]
required
Array of possible values
TypeScript type: Union of enum values SQL type: Custom ENUM type

Custom Types

customType()

Defines a custom column type with custom serialization.

Column Modifiers

All column types support these modifiers:

.notNull()

Marks column as NOT NULL.

.default()

Sets a default value.

.primaryKey()

Marks column as primary key.

.unique()

Adds unique constraint.

.references()

Adds foreign key reference.

.$type()

Overrides TypeScript type without changing runtime behavior.