Database
db_query:where
Server
Appends a filter condition to the query
Syntax
local query = db_query:where(column, operator, value)This function only prepares the query and does not execute it. Chain db_query:fetch or db_query:execute at the end to retrieve or commit the results.
- Chaining — compatible with
:select,:update, and:deletequery builders - Multiple conditions — chain multiple
:wherecalls to apply additional filters
Parameters
| Type | Name | Description |
|---|---|---|
string | column | Name of the column to filter on |
string | operator | Comparison operator to apply Refer Operators section |
string / number | value | Value to compare the column against |
Returns
| Type | Name | Description |
|---|---|---|
db_query / bool | query | Query builder instance on successful execution, or false on failure |
Operators
| Operator | Description |
|---|---|
"=" | Equal to |
"!=" | Not equal to |
">" | Greater than |
"<" | Less than |
">=" | Greater than or equal to |
"<=" | Less than or equal to |
Examples
local db = database.create("127.0.0.1", "root", "", "vital_sandbox")
--Fetch all players with a score greater than 100
local rows = db:table("players")
:select("id", "name", "score")
:where("score", ">", 100)
:fetch()
--Update the score for a specific player
db:table("players")
:update({ score = 500 })
:where("name", "=", "aviril")
:execute()