self:update
Server
Appends a row update to the query
Syntax
local query = self:update(
data
)This function only prepares the query and does not execute it. Chain db_query:execute at the end to commit the query to the database.
- Chaining — compatible with
:whereto target specific rows for updating - Multiple updates — chain multiple
:updatecalls to append additional column updates - Multiple conditions — chain multiple
:wherecalls to apply additional filters to the update - Without conditions — omitting
:wherewill update all rows in the table
Parameters
| Type | Name | Description |
|---|---|---|
table | data | A key-value table defining the columns to update • Keys represent column names • Values represent the new data to apply — accepted types are string and number |
Returns
| Type | Name | Description |
|---|---|---|
db_query | bool | query | Query builder instance on successful execution, or false on failure |
Examples
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()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 = 0 })
:execute())
if not ok then
engine.print("error", err)
end
end):resume()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 = 1000 })
:update({ rank = "elite" })
:where("name", "=", "aviril")
:where("score", ">=", 500)
:execute())
if not ok then
engine.print("error", err)
end
end):resume()