Database
db_query:select
Server
Specifies the columns to retrieve when executing a fetch query
Syntax
local query = db_query: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 selectionZ - 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")
--Fetch specific columns from the players table
local rows = db:table("players")
:select("id", "name", "score")
:fetch()
--Fetch all columns from the players table
local rows = db:table("players")
:fetch()