Skip to content

Types & Options

Option tables and value shapes referenced throughout the API.

Auto-generated

This page is generated from the source annotations by scripts/gen-api.mjs. Edit the LuaCATS doc comments in the Norm sources, not here.

NormOptions

🔗 Source: src/orm.lua

MemberReturnsDescription
adapterRequired.
foreignKeysEmit SQL FOREIGN KEY constraints from belongsTo relations.
jsonJSON provider for json columns.
logLog every executed statement.
logger
promisePromise provider.
queue_until_readyHold data operations in a queue until the first successful sync()/migrate(), then flush them (default false: run immediately).

adapter field

lua
NormAdapter

Required. An adapter instance (or duck-typed table).

foreignKeys field

lua
(boolean|"auto")?

Emit SQL FOREIGN KEY constraints from belongsTo relations. "auto" (default) emits on MySQL, skips on SQLite (with a one-time warning); true always emits; false never emits (no warning).

json field

lua
("auto"|NormJsonProvider|false)?

JSON provider for json columns. "auto" (default) uses the adapter's, else auto-detects (Nanos JSON / Lua json), else raw passthrough; false disables (de)serialisation.

log field

lua
boolean?

Log every executed statement.

logger field

lua
fun(level: string, message: string)?

promise field

lua
NormPromiseProvider?

Promise provider. Defaults to the adapter's, else built-in.

queue_until_ready field

lua
boolean?

Hold data operations in a queue until the first successful sync()/migrate(), then flush them (default false: run immediately).

NormDefineOptions

Options controlling how a model behaves (3rd arg of define).

🔗 Source: src/model.lua

MemberReturnsDescription
hooksLifecycle hooks per event (see NormModel:hook), as a single handler or a list.
indexesTable indexes emitted at sync() (composite via columns, single via column).
scopesNamed reusable query fragments (see NormModel:scope).
soft_deletesMark rows deleted (set a deleted_at) instead of removing them; queries then exclude them by default.
timestampsAuto-manage created_at/updated_at (Norm-side, UTC; portable across SQLite/MySQL).

hooks field

lua
table<string, fun(record: NormRecord)|fun(record: NormRecord)[]>?

Lifecycle hooks per event (see NormModel:hook), as a single handler or a list.

indexes field

lua
{ columns: string[], column: string, unique: boolean, name: string }[]?

Table indexes emitted at sync() (composite via columns, single via column).

scopes field

lua
table<string, fun(query: NormQueryBuilder, ...any)>?

Named reusable query fragments (see NormModel:scope).

soft_deletes field

lua
(boolean|{ column: string })?

Mark rows deleted (set a deleted_at) instead of removing them; queries then exclude them by default. true uses deleted_at; pass a table to rename.

timestamps field

lua
(boolean|{ created: string, updated: string })?

Auto-manage created_at/updated_at (Norm-side, UTC; portable across SQLite/MySQL). true uses the default names; pass a table to rename.

NormColumn

🔗 Source: src/types.lua

MemberReturnsDescription
autoincrement
defaultLiteral value, or Norm.types.raw(...) for raw SQL.
indexEmit a (non-unique) index on this column at sync().
kind
lengthLength for VARCHAR columns.
nameSet by define() from the schema key.
nullableDefaults to true (false for primary keys).
primary
unique

autoincrement field

lua
boolean?

default field

lua
any

Literal value, or Norm.types.raw(...) for raw SQL.

index field

lua
boolean?

Emit a (non-unique) index on this column at sync().

kind field

lua
NormColumnKind

length field

lua
number?

Length for VARCHAR columns.

name field

lua
string?

Set by define() from the schema key.

nullable field

lua
boolean?

Defaults to true (false for primary keys).

primary field

lua
boolean?

unique field

lua
boolean?

NormColumnOptions

🔗 Source: src/types.lua

MemberReturnsDescription
autoincrement
defaultLiteral value, or Norm.types.raw(...) for raw SQL.
indexEmit a (non-unique) index on this column at sync().
lengthLength for VARCHAR columns.
nullableDefaults to true (false for primary keys).
primary
unique

autoincrement field

lua
boolean?

default field

lua
any

Literal value, or Norm.types.raw(...) for raw SQL.

index field

lua
boolean?

Emit a (non-unique) index on this column at sync().

length field

lua
number?

Length for VARCHAR columns.

nullable field

lua
boolean?

Defaults to true (false for primary keys).

primary field

lua
boolean?

unique field

lua
boolean?

NormRelationOptions

🔗 Source: src/types.lua

MemberReturnsDescription
keyFK column name.
localKeyLocal column for has_*/belongs_to_many (defaults to this model's primary key).
onDeleteEmitted as ON DELETE … on the FK (belongs_to only).
onUpdateEmitted as ON UPDATE … on the FK (belongs_to only).
otherKeyReferenced column / target-side pivot FK (defaults to the relevant primary key).
otherLocalKeyTarget's local column for belongs_to_many (defaults to the target's primary key).
throughPivot (join) table for belongs_to_many (defaults to the two singulars joined alphabetically).

key field

lua
string?

FK column name. See each relation for its default.

localKey field

lua
string?

Local column for has_*/belongs_to_many (defaults to this model's primary key).

onDelete field

lua
NormReferentialAction?

Emitted as ON DELETE … on the FK (belongs_to only).

onUpdate field

lua
NormReferentialAction?

Emitted as ON UPDATE … on the FK (belongs_to only).

otherKey field

lua
string?

Referenced column / target-side pivot FK (defaults to the relevant primary key).

otherLocalKey field

lua
string?

Target's local column for belongs_to_many (defaults to the target's primary key).

through field

lua
string?

Pivot (join) table for belongs_to_many (defaults to the two singulars joined alphabetically).

NormMigration

🔗 Source: src/orm.lua

MemberReturnsDescription
idUnique, stable identifier (applied once).
upReceives the schema builder; record changes via m:add_column(...) etc.

id field

lua
string

Unique, stable identifier (applied once). Order them by sorting-friendly ids.

up field

lua
fun(m: table)

Receives the schema builder; record changes via m:add_column(...) etc.

NormForeignKey

A foreign-key constraint to emit inside CREATE TABLE.

🔗 Source: src/sql.lua

MemberReturnsDescription
columnFK column on this table.
on_deleteReferential action (e.g.
on_updateReferential action (e.g.
ref_columnReferenced column.
ref_tableReferenced table.

column field

lua
string

FK column on this table.

on_delete field

lua
string?

Referential action (e.g. "CASCADE").

on_update field

lua
string?

Referential action (e.g. "CASCADE").

ref_column field

lua
string

Referenced column.

ref_table field

lua
string

Referenced table.

NormExecResult

🔗 Source: src/adapter.lua

MemberReturnsDescription
affectedRows
insertId

affectedRows field

lua
number?

insertId field

lua
any

NormQueryState

🔗 Source: src/sql.lua

MemberReturnsDescription
columnsSelected columns (nil = "*").
groupsGROUP BY columns.
havingsHAVING conditions (ANDed).
joinsJOIN clauses.
limit
offset
orders
raw_columnsRaw (unquoted) select expressions, e.g.
table
wheres

columns field

lua
string[]?

Selected columns (nil = "*").

groups field

lua
string[]?

GROUP BY columns.

havings field

lua
NormHaving[]?

HAVING conditions (ANDed).

joins field

lua
NormJoin[]?

JOIN clauses.

limit field

lua
number?

offset field

lua
number?

orders field

lua
NormOrder[]?

raw_columns field

lua
string[]?

Raw (unquoted) select expressions, e.g. "COUNT(*) AS n".

table field

lua
string

wheres field

lua
NormWhere[]

NormDialect

🔗 Source: src/dialect.lua

MemberReturnsDescription
autoincrement
name
placeholder
quote
table_suffix
types

autoincrement field

lua
string

name field

lua
string

placeholder field

lua
fun(index: number):string

quote field

lua
fun(id: string):string

table_suffix field

lua
string

types field

lua
table<string, string>

NormPromiseProvider

A promise provider plugs a framework's promise type into Norm. Built-in builders: Norm.promise.builtin|nanos|cfx. Validate a custom one with Norm.promise.define.

🔗 Source: src/promise.lua

MemberReturnsDescription
is_promise
name
newReturns a framework promise.
rejectAlready-rejected promise.
resolveAlready-resolved promise.

is_promise field

lua
(fun(value: any):boolean)?

name field

lua
string

new field

lua
fun(executor: fun(resolve: fun(value: any), reject: fun(reason: any))):any

Returns a framework promise.

reject field

lua
fun(reason: any):any

Already-rejected promise.

resolve field

lua
fun(value: any):any

Already-resolved promise.

NormJsonProvider

A JSON provider plugs a host's JSON library into Norm.

🔗 Source: src/json.lua

MemberReturnsDescription
decode
encode
name

decode field

lua
fun(text: string):any

encode field

lua
fun(value: any):string

name field

lua
string