Vital.sandbox
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 :where to apply filters to the selection
  • Multiple selections — chain multiple :select calls to append additional columns to the selectionZ
  • Without selections — all columns are returned, equivalent to SELECT *
  • Multiple conditions — chain multiple :where calls to apply additional filters

Parameters

TypeNameDescription
string...One or more column names to retrieve from the table
Omit to return all columns

Returns

TypeNameDescription
db_query / boolqueryQuery 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()

On this page