Database
db_query:insert
Server
Appends a row insertion to the query
Syntax
local query = db_query: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.
- Data — accepts a key-value table where each key is a column name and each value is the data to insert
- 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")
--Insert a new player record
db:table("players")
:insert({ name = "aviril", score = 0 })
:execute()