self:insert
Server
Appends a row insertion to the query
Syntax
local query = self:insert(
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.
- Multiple insertions — chain multiple
:insertcalls to append additional row insertions
Parameters
| Type | Name | Description |
|---|---|---|
table | data | A key-value table defining the row to insert • Keys represent column names • Values represent the data to insert — 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")
:insert({ name = "aviril", 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")
:insert({ name = "aviril", score = 0 })
:insert({ name = "xaero", score = 100 })
:execute())
if not ok then
engine.print("error", err)
end
end):resume()