db_query
db_query(sql, [params]) executes a SELECT query on the SQLite database. Returns an array of row-tables with column-value pairs.
Signature
Section titled “Signature”db_query(sql, [params])
asyncParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
sql |
string | The SQL SELECT statement |
params |
table? | Optional array of positional parameters for prepared statements (? placeholders) |
Returns
Section titled “Returns”| Value | Type | Description |
|---|---|---|
| rows | array | Array of row tables with column-value pairs |
Example
Section titled “Example”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)endSee Also
Section titled “See Also”- db_exec - Execute INSERT/UPDATE/DELETE statements