Overview
TheDBField interface represents a column in a database table with its data type, constraints, and metadata.
Interface Definition
Properties
Unique identifier for the field
Column name in the database
Data type of the field. Contains:
id: Type identifier (e.g.,'varchar','integer')name: Display name of the type
varchar, text, integer, bigint, decimal, boolean, timestamp, uuid, json, jsonbWhether this field is part of the primary key
Whether this field has a unique constraint
Whether this field accepts NULL values. Primary keys are always non-nullable.
Whether this is an auto-increment field:
- PostgreSQL:
SERIAL,BIGSERIAL, orGENERATED BY DEFAULT AS IDENTITY - MySQL/MariaDB:
AUTO_INCREMENT - SQL Server:
IDENTITY(1,1) - SQLite:
AUTOINCREMENT
Whether this field is an array type (PostgreSQL/CockroachDB only).Examples:
integer[], text[], varchar(50)[]Timestamp when the field was created (milliseconds since epoch)
Maximum length for character types (VARCHAR, CHAR).Can be:
- A number:
'255','100' - Special value:
'max'(SQL Server for VARCHAR(MAX))
Precision for numeric types (DECIMAL, NUMERIC, FLOAT).For DECIMAL(10, 2), precision is 10.
Scale for numeric types (DECIMAL, NUMERIC).For DECIMAL(10, 2), scale is 2.
Default value expression for the field.Examples:
- String literals:
'active','pending' - Numbers:
0,100 - Functions:
CURRENT_TIMESTAMP,gen_random_uuid(),NOW() - Boolean:
TRUE,FALSE - NULL:
NULL
Character collation for string types (e.g.,
'utf8_general_ci', 'en_US.UTF-8')Field-level comments/description (supported in PostgreSQL, MySQL, SQL Server)
Field-level check constraint expression (e.g.,
'price > 0')Zod Schema
Helper Functions
generateDBFieldSuffix
Generates the type suffix for display (e.g.,(255) for VARCHAR, (10, 2) for DECIMAL):
Examples
Primary Key Field
Auto-Increment Field (PostgreSQL)
VARCHAR Field with Length
DECIMAL Field with Precision and Scale
Array Field (PostgreSQL)
Timestamp with Default
Data Type Support by Database
| Type | PostgreSQL | MySQL | SQL Server | SQLite |
|---|---|---|---|---|
| VARCHAR | ✅ | ✅ | ✅ | ✅ (as TEXT) |
| INTEGER | ✅ | ✅ | ✅ | ✅ |
| DECIMAL | ✅ | ✅ | ✅ | ✅ (as REAL) |
| BOOLEAN | ✅ | ✅ (TINYINT) | ✅ (BIT) | ✅ (INTEGER) |
| UUID | ✅ | ❌ | ✅ (UNIQUEIDENTIFIER) | ❌ |
| JSON | ✅ | ✅ | ❌ | ❌ |
| JSONB | ✅ | ❌ | ❌ | ❌ |
| Arrays | ✅ | ❌ | ❌ | ❌ |
