Downtown Chronicles
LibraryModulesKVP

Schema

register validation and bind a collection name.

local Store = lib.kvp.schema(collection, schema)
collectionstring — prefix / collection name
schemafield → { type = 'string' | 'number' | 'table' | 'array', required?, default?, schema? } or shorthand 'string' etc.

Returns: a table with get, put, delete, clear, list

lib.kvp.schema('my_items', {
    label = 'string',
    count = { type = 'number', required = true, default = 1 },
})

local doc = lib.kvp.get('my_items', 'item_1')
lib.kvp.put('my_items', 'item_1', { label = 'Ammo', count = 10 })

Methods on Store

Assume the schema name is my_items.

get(schema, id)

Parametersschemastring; idstring
ReturnsDecoded value or nil

put(schema, id, data)

Parametersschemastring; idstring; data — table (validated)
Returnsnothing; errors if validation fails

delete(schema, id)

Parametersschemastring; idstring
Returnsnothing

clear(schema)

Parametersschemastring
Returnsnothing

list(schema, options?)

Parametersschemastring; options{ take?, skip?, filter? }
Returns{ results = table<string, any>, count = integer }

See also: low-level

On this page