self:execute

Server

Commits the prepared query on the database


Syntax

local promise = self:execute()

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

  • Inside a threadself:await(db_query:execute()) yields until the operation 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 on failure
boolresolvedtrue
stringrejectedError message describing the failure

Examples

Insert a new player record
local db = database.create("127.0.0.1", "root", "", "vital_sandbox")

thread.create(function(self)
    local ok, err = self:await(db:table("players")
        :insert({ name = "aviril", score = 0 })
        :execute())

    if not ok then
        engine.print("error", err)
    end
end):resume()
Update the score for a specific player
local db = database.create("127.0.0.1", "root", "", "vital_sandbox")

thread.create(function(self)
    local ok, err = self:await(db:table("players")
        :update({ score = 500 })
        :where("name", "=", "aviril")
        :execute())

    if not ok then
        engine.print("error", err)
    end
end):resume()
Delete a specific player record
local db = database.create("127.0.0.1", "root", "", "vital_sandbox")

thread.create(function(self)
    local ok, err = self:await(db:table("players")
        :delete()
        :where("name", "=", "aviril")
        :execute())

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

On this page