self:sync

Server

Synchronises all defined table schemas with the database, creating any tables that do not already exist


Syntax

local promise = self:sync()

This function returns a promise and starts processing the query. Use thread:await inside a thread to retrieve the result.

  • Inside a threadself:await(database:sync()) yields until the sync completes, then returns the resolved values.
  • Outside a thread — the promise can still be created, but must be awaited from within a thread to retrieve the result.

Parameters

No parameters are accepted by this function

Returns

TypeNameDescription
promisepromiseRefer Settlements section

Settlements

TypeNameDescription
boolstatustrue on success, false otherwise
boolresolvedtrue
stringrejectedError message describing the failure

Examples

Define and sync the 'players' table
local entity = core.database.create("127.0.0.1", "root", "", "vital_sandbox")

entity:define("players", {
    id = { type = "INT UNSIGNED", primary = true, autoincrement = true, nullable = false },
    name = { type = "VARCHAR(64)", nullable = false },
    score = { type = "INT", nullable = true }
})

util.thread.create(function(self)
    local ok, err = self:await(entity:sync())

    if not ok then
        core.engine.print("error", err)
    end
end):resume()

On this page