Common Options
Options that apply to all field types.| Option | Type | Description | Default |
|---|---|---|---|
name | string | Field name (snake_case) | required |
type | string | Data type | required |
desc | string | Field description | - |
nullable | boolean | Allow NULL | false |
toFilter | boolean | Enable search filtering | false |
dbDefault | string | Database default value | - |
generated | GeneratedColumn | Computed column setting | - |
Generated Column
A column that automatically generates computed values.type:STORED|VIRTUALSTORED: Physically stored (can create indexes)VIRTUAL: Calculated only on query (saves memory)
expression: SQL expression
Numeric Types
integer / integer[]
32-bit integer type.- Single Value
- Array
- PostgreSQL:
integer - TypeScript:
number - JSON:
number
bigInteger / bigInteger[]
64-bit integer type.- Single Value
- Array
- PostgreSQL:
bigint - TypeScript:
bigint - JSON:
bigint(serialized as string)
number / number[]
Floating-point or fixed-point numeric type.- Single Value
- Array
- PostgreSQL:
numeric(10, 2)(default) - TypeScript:
number - JSON:
number
precision: Total digits (default: none = unlimited)scale: Decimal places (default: 0)numberType:numeric|real|double precision(default:numeric)
| Type | Precision | Memory | Use Cases |
|---|---|---|---|
numeric | Exact (recommended) | High | Money, currency |
real | Approximate (6 digits) | 4 bytes | Scientific data |
double precision | Approximate (15 digits) | 8 bytes | Coordinates, measurements |
numeric / numeric[]
High-precision numeric type. Processed as string in TypeScript.- Single Value
- Array
- PostgreSQL:
numeric(20, 10) - TypeScript:
string⚠️ - JSON:
string
precision: Total digitsscale: Decimal places
String Types
string / string[]
Variable-length string type.- Single Value
- Array
- PostgreSQL:
varchar(255)(when length specified) ortext - TypeScript:
string - JSON:
string
length: Maximum length (usestexttype when omitted)zodFormat: Zod 4 String Format validation (see below)
zodFormat Option
ThezodFormat option automatically applies Zod’s string format validation when generating BaseSchema.
Usage Example:
| Category | Format | Description |
|---|---|---|
| Basic | email | Email address format |
uuid | UUID format | |
url | URL format | |
httpUrl | HTTP/HTTPS URL format | |
hostname | Hostname format | |
emoji | Emoji format | |
jwt | JWT token format | |
| Encoding | base64 | Base64 encoding |
base64url | URL-safe Base64 encoding | |
hex | Hexadecimal string | |
| ID | nanoid | NanoID format |
cuid | CUID format | |
cuid2 | CUID2 format | |
ulid | ULID format | |
| Network | ipv4 | IPv4 address |
ipv6 | IPv6 address | |
mac | MAC address | |
cidrv4 | IPv4 CIDR notation | |
cidrv6 | IPv6 CIDR notation | |
| Hash | hashMd5 | MD5 hash |
hashSha1 | SHA-1 hash | |
hashSha256 | SHA-256 hash | |
hashSha384 | SHA-384 hash | |
hashSha512 | SHA-512 hash | |
| ISO | isoDate | ISO 8601 date (YYYY-MM-DD) |
isoTime | ISO 8601 time (HH:MM:SS) | |
isoDatetime | ISO 8601 datetime | |
isoDuration | ISO 8601 duration |
enum / enum[]
Enumeration type. Only values defined in the Entity’senums are allowed.
- Single Value
- Array
- PostgreSQL:
text - TypeScript:
"admin" | "normal"(Union of Enum keys) - JSON:
string
id: Enum type ID (must be defined in Entity’senums)length: String max length (optional)
Learn More - Enums - Detailed Enum guide
Boolean Type
boolean / boolean[]
Type for storing true/false values.- Single Value
- Array
- PostgreSQL:
boolean - TypeScript:
boolean - JSON:
boolean
Date/Time Types
date / date[]
Type for storing date and time.- Single Value
- Array
- PostgreSQL:
timestamptz(with timezone) - TypeScript:
Date - JSON:
string(ISO 8601 format)
UUID Type
uuid / uuid[]
Universally Unique Identifier (UUID) type.- Single Value
- Array
- PostgreSQL:
uuid - TypeScript:
string - JSON:
string
UUID Generation: Using PostgreSQL’s
gen_random_uuid() function as dbDefault enables
auto-generation.Structured Data Types
json
Type for storing structured data in JSON format.- PostgreSQL:
json - TypeScript: User-defined type (
ProductMetadata) - JSON:
any
id: TypeScript type ID (defined in.types.ts)
virtual
Virtual fields not stored in the database.- PostgreSQL: Not stored
- TypeScript: User-defined type (or
string,number, etc.) - JSON: Included (after calculation)
id: TypeScript type IDvirtualType:code|query(default:code)code: Calculated with TypeScript codequery: Calculated with SQL appendSelect
- code
- query
Calculated with TypeScript code in Model.Pros: Can implement complex logic, can call external APIs
Cons: Cannot filter/sort at database level
Vector Types
vector / vector[]
Type for storing vector embeddings. Requires pgvector extension.- Single Value
- Array
- PostgreSQL:
vector(1536)(pgvector extension) - TypeScript:
number[] - JSON:
number[]
dimensions: Vector dimensions (required, e.g., 1536)
Learn More - Vector Search - Detailed vector
search guide - pgvector - PostgreSQL vector extension
tsvector
Type for PostgreSQL Full-Text Search.- PostgreSQL:
tsvector - TypeScript:
string - JSON:
string
Full-Text Search: A type optimized for keyword searching in natural language text. Supports
morphological analysis, stemming, etc.
Relation Type
Type for defining relationships with other Entities.BelongsToOne: N:1 relationshipOneToOne: 1:1 relationshipHasMany: 1:N relationshipManyToMany: N:M relationship
Learn More - Relations - Detailed Relation guide
Type Selection Guide
Storing Numbers
| Data | Type | Reason |
|---|---|---|
| ID, age, count | integer | Common integers |
| Large ID, timestamp | bigInteger | Large range needed |
| Money, price | number (precision, scale) | Precise decimals |
| Scientific measurements | number (numberType: real) | Approximate values allowed |
| High-precision calculations | numeric | Prevent precision loss |
Storing Strings
| Data | Type | Reason |
|---|---|---|
| Name, email | string (length: 255) | Common text |
| Description, content | string (omit length) | Long text |
| Status, role | enum | Limited value list |
| UUID, token | uuid | Unique identifier |
Storing Date/Time
| Data | Type | Setting |
|---|---|---|
| Created at | date | dbDefault: "CURRENT_TIMESTAMP" |
| Updated at | date | Update trigger needed |
| Date only | date | Time is 00:00:00 |
Complex Data
| Data | Type | Reason |
|---|---|---|
| Settings, metadata | json | Structured data |
| Computed fields | virtual | No storage needed |
| Text embeddings | vector | AI search |
| Full-text search | tsvector | Keyword search |
Next Steps
Relations
Define Entity relationships
Enums
Using Enum types
Indexes
Improve search performance with indexes
Vector Search
Setting up Vector search