#api/syscall

The Datastore API provides functions for interacting with a key-value store that has query capabilities.

  • Keys are represented as a list (Lua table) of strings.
  • Values can be any persistable value.

Key-Value Operations

datastore.set(key, value)

Sets a value in the key-value store.

Example:

datastore.set({"user","123"}, {name = "John", age = 30})

datastore.get(key)

Gets a value from the key-value store.

Example:

local user = datastore.get({"user","123"})
print(user.name)  -- prints "John"

datastore.del(key)

Deletes a value from the key-value store.

Example:

datastore.del({"user", "123"})

Batch Operations

datastore.batchSet(kvs)

Sets multiple key-value pairs in a single operation.

Example:

local kvs = {
    {key = {"user", "1"}, value = {name = "Alice"}},
    {key = {"user", "2"}, value = {name = "Bob"}}
}
datastore.batchSet(kvs)

datastore.batchGet(keys)

Gets multiple values in a single operation.

Example:

local keys = {{"user", "1"}, {"user", "2"}}
local values = datastore.batchGet(keys)
for _, value in ipairs(values) do
    print(value.name)
end

datastore.batchDel(keys)

Deletes multiple values in a single operation.

Example: ```lua local keys = {{"user", "1"}, {"user", "2"}} datastore.batchDel(keys)