Data Types

Available data types for model columns, with database-specific mappings

DataTypes Enum

types.tstypescript
export enum DataTypes {
STRING, // Maps to VARCHAR or TEXT
TEXT, // Maps to TEXT
INTEGER, // Maps to INTEGER or INT
BIGINT, // Maps to BIGINT
FLOAT, // Maps to REAL or FLOAT
DOUBLE, // Maps to DOUBLE PRECISION
DECIMAL, // Maps to DECIMAL or NUMERIC
BOOLEAN, // Maps to BOOLEAN or TINYINT/INTEGER
DATE, // Maps to DATE or TEXT
DATETIME, // Maps to TIMESTAMP, DATETIME, or TEXT
JSON, // Maps to JSON, JSONB, or TEXT
UUID, // Maps to UUID or VARCHAR(36)
BLOB, // Maps to BYTEA or BLOB
}

Abstract data types for model columns, mapped to native SQL column types per database.

Database Type Mappings

How each DataTypes value maps to native column types in major databases:

DataTypePostgresMySQLSQLite
DataTypes.STRINGTEXTVARCHAR(255)TEXT
DataTypes.TEXTTEXTTEXTTEXT
DataTypes.INTEGERINTEGERINTINTEGER
DataTypes.BIGINTBIGINTBIGINTINTEGER
DataTypes.FLOATREALFLOATREAL
DataTypes.DOUBLEDOUBLE PRECISIONDOUBLEREAL
DataTypes.DECIMALDECIMALDECIMAL(10,2)NUMERIC
DataTypes.BOOLEANBOOLEANTINYINT(1)INTEGER
DataTypes.DATEDATEDATETEXT
DataTypes.DATETIMETIMESTAMPDATETIMETEXT
DataTypes.JSONJSONBJSONTEXT
DataTypes.UUIDUUIDCHAR(36)TEXT
DataTypes.BLOBBYTEABLOBBLOB
mapDataTypeToSql.tstypescript
function mapDataTypeToSql(dt: DataTypes | string, dbType: DBType): string {
// ...see codebase implementation above...
}

String Types

DataTypes.STRING→ VARCHAR / TEXT / VARCHAR(255)

Variable-length string with specified max length.

{ type: DataTypes.STRING, length: 255 }
DataTypes.TEXT→ TEXT

Large text content without length limit.

{ type: DataTypes.TEXT }

Numeric Types

DataTypes.INTEGER→ INTEGER / INT

Whole numbers.

{ type: DataTypes.INTEGER, autoIncrement: true }
DataTypes.BIGINT→ BIGINT

Large whole numbers.

{ type: DataTypes.BIGINT }
DataTypes.FLOAT→ FLOAT / REAL

Floating-point numbers.

{ type: DataTypes.FLOAT }
DataTypes.DOUBLE→ DOUBLE PRECISION / DOUBLE

Double-precision floating-point numbers.

{ type: DataTypes.DOUBLE }
DataTypes.DECIMAL→ DECIMAL / NUMERIC

Precise decimal numbers (currency, etc.).

{ type: DataTypes.DECIMAL, precision: 10, scale: 2 }

Boolean Type

DataTypes.BOOLEAN→ BOOLEAN / TINYINT(1) / INTEGER

True/false values.

{ type: DataTypes.BOOLEAN, defaultValue: false }

Date & Time Types

DataTypes.DATETIME→ TIMESTAMP / DATETIME / TEXT

Date and time with timezone.

{ type: DataTypes.DATETIME, defaultValue: () => new Date() }
DataTypes.DATE→ DATE / TEXT

Date only (no time).

{ type: DataTypes.DATE }
DataTypes.TIME→ TIME

Time only (no date).

{ type: DataTypes.TIME }

Special Types

DataTypes.JSON→ JSON / JSONB / TEXT

JSON data (objects, arrays).

{ type: DataTypes.JSON }
DataTypes.UUID→ UUID / CHAR(36) / TEXT

Universally unique identifier.

{ type: DataTypes.UUID, defaultValue: () => crypto.randomUUID() }
DataTypes.BLOB→ BYTEA / BLOB

Binary large object (file, image, etc.).

{ type: DataTypes.BLOB }

Complete Example

models/Product.tstypescript
import { defineModel, DataTypes } from "stabilize-orm";
const Product = defineModel({
tableName: "products",
columns: {
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: () => crypto.randomUUID(),
},
name: {
type: DataTypes.STRING,
length: 255,
required: true,
},
description: {
type: DataTypes.TEXT,
},
price: {
type: DataTypes.DECIMAL,
precision: 10,
scale: 2,
required: true,
},
stock: {
type: DataTypes.INTEGER,
defaultValue: 0,
},
isAvailable: {
type: DataTypes.BOOLEAN,
defaultValue: true,
},
metadata: {
type: DataTypes.JSON,
},
image: {
type: DataTypes.BLOB,
},
releaseDate: {
type: DataTypes.DATE,
},
createdAt: {
type: DataTypes.DATETIME,
defaultValue: () => new Date(),
},
},
});