Storage
DlmpDbValue
Type: nil|boolean|integer|number|string
DlmpDbParams
Positions 1..n, where n is the n field (table.pack) or the highest index; a nil in between is NULL.
Type: DlmpDbValue[]
DlmpDbRow
One row by column name; a NULL column is absent. Use AS to rename duplicate columns.
Type: table<string, DlmpDbValue>
DlmpDb
The resource's own storage namespace. The server keeps one per resource and applies the resource's migrations ([storage.migrations] sqlite = ["migrations/sqlite/001_init.sql", ...], in order, each once; a migration must not be edited after it has run) before its scripts run. No resource can access another's. SQL is the dialect of the server's backend (SQLite: ? placeholders, RETURNING, ON CONFLICT); a statement may read and change rows, but the schema changes only in a migration.
Every call queues its request and returns immediately: true, or nil, err when 256 requests are already waiting. The result reaches the callback in a later server step, in request order; a stopped resource receives no callbacks, but its queued writes still run. A malformed argument (a table or non-UTF-8 string parameter, SQL over 64 KiB, more than 256 parameters) raises an error. Limits: 10 000 rows and 16 MiB per result, 1 MiB per value, 5 s per statement or transaction.
DlmpDb.query
Runs one statement and passes its rows to callback(rows), or calls callback(nil, err).
Parameters
sqlstringparams(optional)DlmpDbParamscallbackfun(rows: DlmpDbRow[]|nil, err: string|nil)
Returns ok true|nil, err string|nil
DlmpDb.exec
Runs one statement that returns no rows and calls callback(changed_rows) or callback(nil, err). Without a callback, a failure is written to the server log.
Parameters
sqlstringparams(optional)DlmpDbParamscallback(optional)fun(changes: integer|nil, err: string|nil)
Returns ok true|nil, err string|nil
DlmpDb.transaction
Runs 1..256 statements as one transaction (all or none), then calls callback(true) or callback(nil, err), where err gives the number of the failed statement. No Lua runs between statements, so put conditions in the SQL (WHERE money >= ?).
Parameters
statements{ [1]: string, [2]: DlmpDbParams|nil }[]callback(optional)fun(ok: true|nil, err: string|nil)
Returns ok true|nil, err string|nil
