Skip to content

Column Types

Sleet ORM supports all common MySQL column types with their corresponding Lua types.

Numeric Types

sl.serial()

Auto-incrementing integer, typically used for primary keys.

  • MySQL: INT AUTO_INCREMENT
  • Lua: integer
lua
id = sl.serial().primaryKey()

sl.bigserial()

Auto-incrementing big integer for large datasets.

  • MySQL: BIGINT AUTO_INCREMENT
  • Lua: integer
lua
id = sl.bigserial().primaryKey()

sl.int()

Standard integer.

  • MySQL: INT
  • Lua: integer
  • Range: -2,147,483,648 to 2,147,483,647
lua
money = sl.int().default(1000)

sl.bigint()

Large integer for big numbers.

  • MySQL: BIGINT
  • Lua: integer
  • Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
lua
experience = sl.bigint().default(0)

sl.smallint()

Small integer.

  • MySQL: SMALLINT
  • Lua: integer
  • Range: -32,768 to 32,767
lua
level = sl.smallint().default(1)

sl.tinyint()

Very small integer.

  • MySQL: TINYINT
  • Lua: integer
  • Range: -128 to 127 (or 0 to 255 if unsigned)
lua
status = sl.tinyint().default(0)

sl.float()

Single-precision floating point.

  • MySQL: FLOAT
  • Lua: number
lua
rating = sl.float()

sl.double()

Double-precision floating point.

  • MySQL: DOUBLE
  • Lua: number
lua
coordinates_x = sl.double()

sl.decimal(precision, scale)

Fixed-point decimal for exact numeric values.

  • MySQL: DECIMAL(precision, scale)
  • Lua: number
  • Use for: Money, precise calculations
lua
price = sl.decimal(10, 2)  -- Up to 99,999,999.99
balance = sl.decimal(15, 4) -- High precision

String Types

sl.varchar(length)

Variable-length string.

  • MySQL: VARCHAR(length)
  • Lua: string
  • Max length: 65,535 characters
lua
name = sl.varchar(255).notNull()
email = sl.varchar(100).unique()

sl.char(length)

Fixed-length string.

  • MySQL: CHAR(length)
  • Lua: string
  • Use for: Codes, fixed-format data
lua
country_code = sl.char(2)  -- ISO country codes
license_plate = sl.char(8)

sl.text()

Large text field.

  • MySQL: TEXT
  • Lua: string
  • Max length: 65,535 characters
lua
description = sl.text()
notes = sl.text()

sl.longtext()

Very large text field.

  • MySQL: LONGTEXT
  • Lua: string
  • Max length: 4,294,967,295 characters
lua
log_data = sl.longtext()

Date and Time Types

sl.timestamp()

Timestamp with timezone.

  • MySQL: TIMESTAMP
  • Lua: string (ISO format)
  • Range: 1970-2038
lua
created_at = sl.timestamp().defaultNow()
updated_at = sl.timestamp().onUpdate(sl.sql('NOW()'))

sl.datetime()

Date and time without timezone.

  • MySQL: DATETIME
  • Lua: string (ISO format)
  • Range: 1000-9999
lua
scheduled_at = sl.datetime()

sl.date()

Date only.

  • MySQL: DATE
  • Lua: string (YYYY-MM-DD format)
lua
birth_date = sl.date()

Other Types

sl.boolean()

Boolean value.

  • MySQL: TINYINT(1)
  • Lua: boolean
lua
is_active = sl.boolean().default(true)
is_admin = sl.boolean().default(false)

sl.json()

JSON data type.

  • MySQL: JSON
  • Lua: table
lua
metadata = sl.json()
settings = sl.json()

Column Modifiers

All column types support these chainable modifiers:

Constraints

.primaryKey()

Mark as primary key.

lua
id = sl.serial().primaryKey()

.notNull()

Add NOT NULL constraint.

lua
name = sl.varchar(255).notNull()

.unique()

Add UNIQUE constraint.

lua
email = sl.varchar(100).unique()
identifier = sl.varchar(64).notNull().unique()

Default Values

.default(value)

Set default value.

lua
money = sl.int().default(1000)
active = sl.boolean().default(true)
role = sl.varchar(50).default('user')

.defaultNow()

Set default to current timestamp (timestamp columns only).

lua
created_at = sl.timestamp().defaultNow()

Special Behaviors

.onUpdate(value)

Auto-update column on row changes.

lua
updated_at = sl.timestamp().onUpdate(sl.sql('NOW()'))
version = sl.int().default(1).onUpdate(sl.sql('version + 1'))

.softDelete()

Mark column as soft delete timestamp.

lua
deleted_at = sl.timestamp().softDelete()

Documentation

.comment(text)

Add column comment (appears in IDE and SQL).

lua
money = sl.int().default(1000).comment('Player cash on hand')

Relationships

.references(column)

Create foreign key reference.

lua
player_id = sl.int().notNull().references(players.id)

Usage Examples

Complete Table Definition

lua
local players = sl.table('players', {
    -- Primary key
    id = sl.serial().primaryKey().comment('Player unique identifier'),
    
    -- Unique identifiers
    identifier = sl.varchar(64).notNull().unique().comment('Steam/Discord ID'),
    license = sl.char(40).unique().comment('FiveM license'),
    
    -- Basic info
    name = sl.varchar(255).notNull().comment('Display name'),
    age = sl.tinyint().comment('Player age'),
    
    -- Money (use decimal for precision)
    money = sl.decimal(10, 2).default(1000.00).comment('Cash on hand'),
    bank = sl.decimal(12, 2).default(5000.00).comment('Bank balance'),
    
    -- Status flags
    is_active = sl.boolean().default(true).comment('Account active'),
    is_admin = sl.boolean().default(false).comment('Admin privileges'),
    
    -- JSON data
    metadata = sl.json().comment('Extended player data'),
    
    -- Timestamps
    created_at = sl.timestamp().defaultNow().comment('Registration date'),
    updated_at = sl.timestamp().defaultNow().onUpdate(sl.sql('NOW()')).comment('Last update'),
    last_seen = sl.timestamp().comment('Last login time'),
    
    -- Soft delete
    deleted_at = sl.timestamp().softDelete().comment('Deletion timestamp')
})

Type Mapping Reference

Sleet TypeMySQL DDLLua TypeUse Case
sl.serial()INT AUTO_INCREMENTintegerPrimary keys
sl.int()INTintegerCounters, IDs, amounts
sl.decimal(10,2)DECIMAL(10,2)numberMoney, prices
sl.varchar(255)VARCHAR(255)stringNames, titles
sl.text()TEXTstringDescriptions, notes
sl.boolean()TINYINT(1)booleanFlags, switches
sl.timestamp()TIMESTAMPstringDates, times
sl.json()JSONtableComplex data

Choose the right column type for your data to ensure optimal performance and storage efficiency!

Released under the MIT License.