Skip to main content
Sonamu supports various data types, and each type is appropriately mapped to PostgreSQL, TypeScript, and JSON.

Common Options

Options that apply to all field types.

Generated Column

A column that automatically generates computed values.
Options:
  • type: STORED | VIRTUAL
    • STORED: Physically stored (can create indexes)
    • VIRTUAL: Calculated only on query (saves memory)
  • expression: SQL expression
  • VIRTUAL type cannot be used with array types, json, or vector - generated and dbDefault cannot be used together

Numeric Types

integer / integer[]

32-bit integer type.
Mapping:
  • PostgreSQL: integer
  • TypeScript: number
  • JSON: number
Range: -2,147,483,648 ~ 2,147,483,647
Use cases: ID, count, age, order, year

bigInteger / bigInteger[]

64-bit integer type.
Mapping:
  • PostgreSQL: bigint
  • TypeScript: bigint
  • JSON: bigint (serialized as string)
Range: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
Values exceeding JavaScript’s Number.MAX_SAFE_INTEGER (2^53 - 1) must use bigint to maintain accuracy.

number / number[]

Floating-point or fixed-point numeric type.
Mapping:
  • PostgreSQL: numeric(10, 2) (default)
  • TypeScript: number
  • JSON: number
Additional Options:
  • precision: Total digits (default: none = unlimited)
  • scale: Decimal places (default: 0)
  • numberType: numeric | real | double precision (default: numeric)
numberType Selection Guide:
Money handling: Setting precision: 10, scale: 2 allows storing up to 99,999,999.99

numeric / numeric[]

High-precision numeric type. Processed as string in TypeScript.
Mapping:
  • PostgreSQL: numeric(20, 10)
  • TypeScript: string ⚠️
  • JSON: string
Additional Options:
  • precision: Total digits
  • scale: Decimal places
Difference between number and numeric:
  • number: number type in TypeScript (possible precision loss)
  • numeric: string type in TypeScript (maintains precision)
Use numeric when you need large numbers or very precise decimal calculations.

String Types

string / string[]

Variable-length string type.
Mapping:
  • PostgreSQL: varchar(255) (when length specified) or text
  • TypeScript: string
  • JSON: string
Additional Options:
  • length: Maximum length (uses text type when omitted)
  • zodFormat: Zod 4 String Format validation (see below)

zodFormat Option

The zodFormat option automatically applies Zod’s string format validation when generating BaseSchema. Usage Example:
Supported Formats:
length Setting Guide: - Short text (name, email): 255 - Long text (description, content): omit (text type) - Fixed length (zip code, phone number): specify exact length
Difference between zodFormat and uuid type: - type: "uuid": Uses PostgreSQL’s native uuid column type, enabling UUID-specific indexes and functions - type: "string" + zodFormat: "uuid": Uses PostgreSQL’s text/varchar column while validating UUID format only at the API level

enum / enum[]

Enumeration type. Only values defined in the Entity’s enums are allowed.
Mapping:
  • PostgreSQL: text
  • TypeScript: "admin" | "normal" (Union of Enum keys)
  • JSON: string
Additional Options:
  • id: Enum type ID (must be defined in Entity’s enums)
  • length: String max length (optional)
Enum Definition Example:
Learn More - Enums - Detailed Enum guide

Boolean Type

boolean / boolean[]

Type for storing true/false values.
Mapping:
  • PostgreSQL: boolean
  • TypeScript: boolean
  • JSON: boolean
Default value setting: dbDefault: "true" or dbDefault: "false"

Date/Time Types

date / date[]

Type for storing date and time.
Mapping:
  • PostgreSQL: timestamptz (with timezone)
  • TypeScript: Date
  • JSON: string (ISO 8601 format)
Commonly used default values: - CURRENT_TIMESTAMP: Current time - CURRENT_DATE: Current date (time 00:00:00)

UUID Type

uuid / uuid[]

Universally Unique Identifier (UUID) type.
Mapping:
  • 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.
Mapping:
  • PostgreSQL: json
  • TypeScript: User-defined type (ProductMetadata)
  • JSON: any
Additional Options:
  • id: TypeScript type ID (defined in .types.ts)
Type Definition Example:
JSON types can be difficult to index and may have lower performance. It’s recommended to separate frequently searched fields into separate columns.

virtual

Virtual fields not stored in the database.
Mapping:
  • PostgreSQL: Not stored
  • TypeScript: User-defined type (or string, number, etc.)
  • JSON: Included (after calculation)
Additional Options:
  • id: TypeScript type ID
  • virtualType: code | query (default: code)
    • code: Calculated with TypeScript code
    • query: Calculated with SQL appendSelect
virtualType Comparison:
Calculated with TypeScript code in Model.
Pros: Can implement complex logic, can call external APIs Cons: Cannot filter/sort at database level
virtualType Selection Guide: - Simple string concatenation, arithmetic calculations → query
  • Complex business logic, external API calls → code

Vector Types

vector / vector[]

Type for storing vector embeddings. Requires pgvector extension.
Mapping:
  • PostgreSQL: vector(1536) (pgvector extension)
  • TypeScript: number[]
  • JSON: number[]
Additional Options:
  • dimensions: Vector dimensions (required, e.g., 1536)
Vector Search Example:
Vector Index:
Learn More - Vector Search - Detailed vector search guide - pgvector - PostgreSQL vector extension

tsvector

Type for PostgreSQL Full-Text Search.
Mapping:
  • PostgreSQL: tsvector
  • TypeScript: string
  • JSON: string
Full-Text Search Index:
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.
Relation Types:
  • BelongsToOne: N:1 relationship
  • OneToOne: 1:1 relationship
  • HasMany: 1:N relationship
  • ManyToMany: N:M relationship
Learn More - Relations - Detailed Relation guide

Type Selection Guide

Storing Numbers

Storing Strings

Storing Date/Time

Complex Data

Next Steps

Relations

Define Entity relationships

Enums

Using Enum types

Indexes

Improve search performance with indexes

Vector Search

Setting up Vector search