self:select
Server
Specifies the columns to retrieve when executing a fetch query
Syntax
local query = self:select(
...
)This function only prepares the query and does not execute it. Chain db_query:fetch at the end to retrieve the results.
- Chaining — compatible with
:whereto apply filters to the selection - Multiple selections — chain multiple
:selectcalls to append additional columns to the selection - Without selections — all columns are returned, equivalent to
SELECT * - Multiple conditions — chain multiple
:wherecalls to apply additional filters
Parameters
| Type | Name | Description |
|---|---|---|
string | ... | One or more column names to retrieve from the table Omit to return all columns |
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, rows = self:await(db:table("players")
:select("id", "name", "score")
:fetch())
if ok then
for i = 1, #rows do
engine.print("info", rows[i].id, rows[i].name, rows[i].score)
end
end
end):resume()local db = database.create("127.0.0.1", "root", "", "vital_sandbox")
thread.create(function(self)
local ok, rows = self:await(db:table("players")
:fetch())
if ok then
for i = 1, #rows do
engine.print("info", rows[i].id, rows[i].name, rows[i].score)
end
end
end):resume()