Skip to content

db_query

db_query(sql, [params]) executes a SELECT query on the SQLite database. Returns an array of row-tables with column-value pairs.

db_query(sql, [params])
async
Param Type Description
sql string The SQL SELECT statement
params table? Optional array of positional parameters for prepared statements (? placeholders)
Value Type Description
rows array Array of row tables with column-value pairs
local rows = db_query("SELECT json FROM records WHERE job_id = ? LIMIT 5", { "my-job" })
for _, row in ipairs(rows) do
local data = json_decode(row.json)
log("Title: " .. data.title)
end
  • db_exec - Execute INSERT/UPDATE/DELETE statements