Schema
register validation and bind a collection name.
local Store = lib.kvp.schema(collection, schema)
| |
|---|
collection | string — prefix / collection name |
schema | field → { 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 })
Assume the schema name is my_items.
| |
|---|
| Parameters | schema — string; id — string |
| Returns | Decoded value or nil |
| |
|---|
| Parameters | schema — string; id — string; data — table (validated) |
| Returns | nothing; errors if validation fails |
| |
|---|
| Parameters | schema — string; id — string |
| Returns | nothing |
| |
|---|
| Parameters | schema — string |
| Returns | nothing |
| |
|---|
| Parameters | schema — string; options — { take?, skip?, filter? } |
| Returns | { results = table<string, any>, count = integer } |
See also: low-level