Module rspamd_sqlite3
Module rspamd_sqlite3
This module provides routines to query sqlite3 databases
Example:
local sqlite3 = require "rspamd_sqlite3"
local db = sqlite3.open("/tmp/db.sqlite")
if db then
db:exec([[ CREATE TABLE x (id INT, value TEXT); ]])
db:exec([[ INSERT INTO x VALUES (?1, ?2); ]], 1, 'test')
for row in db:rows([[ SELECT * FROM x ]]) do
print(string.format('%d -> %s', row.id, row.value))
end
end
Brief content:
Functions:
Function | Description |
---|---|
rspamd_sqlite3.open(path) | Opens sqlite3 database at the specified path. |
rspamd_sqlite3:sql(query[, args..]) | Performs sqlite3 query replacing '?1', '?2' and so on with the subsequent args. |
rspamd_sqlite3:rows(query[, args..]) | Performs sqlite3 query replacing '?1', '?2' and so on with the subsequent args. |
Functions
The module rspamd_sqlite3
defines the following functions.
Function rspamd_sqlite3.open(path)
Opens sqlite3 database at the specified path. DB is created if not exists.
Parameters:
path {string}
: path to db
Returns:
{sqlite3}
: sqlite3 handle
Back to module description.
Function rspamd_sqlite3:sql(query[, args..])
Performs sqlite3 query replacing '?1', '?2' and so on with the subsequent args of the function
Parameters:
query {string}
: SQL queryargs... {string|number}
: variable number of arguments
Returns:
{boolean}
:true
if a statement has been successfully executed
Back to module description.
Function rspamd_sqlite3:rows(query[, args..])
Performs sqlite3 query replacing '?1', '?2' and so on with the subsequent args of the function. This function returns iterator suitable for loop construction:
Parameters:
query {string}
: SQL queryargs... {string|number}
: variable number of arguments
Returns:
{function}
: iterator to get all rows
Example:
for row in db:rows([[ SELECT * FROM x ]]) do
print(string.format('%d -> %s', row.id, row.value))
end
Back to module description.
Back to top.