Vital.sandbox
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 :delete query builders
  • Multiple conditions — chain multiple :where calls to apply additional filters

Parameters

TypeNameDescription
stringcolumnName of the column to filter on
stringoperatorComparison operator to apply
Refer Operators section
string / numbervalueValue to compare the column against

Returns

TypeNameDescription
db_query / boolqueryQuery builder instance on successful execution, or false on failure

Operators

OperatorDescription
"="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()

On this page