rspamd_sqlite3
This module provides routines to query sqlite3 databases
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
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. |
The module rspamd_sqlite3
defines the following functions.
rspamd_sqlite3.open(path)
Opens sqlite3 database at the specified path. DB is created if not exists.
Parameters:
path {string}
: path to dbReturns:
{sqlite3}
: sqlite3 handleBack to module description.
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 argumentsReturns:
{boolean}
: true
if a statement has been successfully executedBack to module description.
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 argumentsReturns:
{function}
: iterator to get all rowsfor 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.