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
adapter—Required.
foreignKeys—Emit SQL FOREIGN KEY constraints from belongsTo relations.
json—JSON provider for json columns.
log—Log every executed statement.
logger—
promise—Promise provider.
queue_until_ready—Hold 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
hooks—Lifecycle hooks per event (see NormModel:hook), as a single handler or a list.
indexes—Table indexes emitted at sync() (composite via columns, single via column).
scopes—Named reusable query fragments (see NormModel:scope).
soft_deletes—Mark rows deleted (set a deleted_at) instead of removing them; queries then exclude them by default.
timestamps—Auto-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—
default—Literal value, or Norm.types.raw(...) for raw SQL.
index—Emit a (non-unique) index on this column at sync().
kind—
length—Length for VARCHAR columns.
name—Set by define() from the schema key.
nullable—Defaults 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—
default—Literal value, or Norm.types.raw(...) for raw SQL.
index—Emit a (non-unique) index on this column at sync().
length—Length for VARCHAR columns.
nullable—Defaults 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
key—FK column name.
localKey—Local column for has_*/belongs_to_many (defaults to this model's primary key).
onDelete—Emitted as ON DELETE … on the FK (belongs_to only).
onUpdate—Emitted as ON UPDATE … on the FK (belongs_to only).
otherKey—Referenced column / target-side pivot FK (defaults to the relevant primary key).
otherLocalKey—Target's local column for belongs_to_many (defaults to the target's primary key).
through—Pivot (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
id—Unique, stable identifier (applied once).
up—Receives 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
column—FK column on this table.
on_delete—Referential action (e.g.
on_update—Referential action (e.g.
ref_column—Referenced column.
ref_table—Referenced 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
columns—Selected columns (nil = "*").
groups—GROUP BY columns.
havings—HAVING conditions (ANDed).
joins—JOIN clauses.
limit—
offset—
orders—
raw_columns—Raw (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—
new—Returns a framework promise.
reject—Already-rejected promise.
resolve—Already-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