Convenience and utility functions for the raw_sqlite3 library.
NOTE: Currently the interface of the module should NOT be considered stable since it's mostly a convenience, high-level functions. Users of the library are expected to use sqlite3_nif module directly to build their own high-level primitives since its interface is as stable as the SQLite C API and is thoroughly type-specced and covered by tests.query_parameter() = number() | true | false | nil | undefined | {text, utf8str()} | {blob, iodata()}
abstract datatype: sqlite3()
A database connection handle.
abstract datatype: sqlite3_error_code()
sqlite3 error codes as atoms.
abstract datatype: sqlite3_stmt()
A prepared SQL statement.
abstract datatype: utf8str()
A iodata()
term which, when serialised, should
form a valid UTF8-encoded character string.
atom_to_int_flag/1 | Convert an atom into an integer flag. |
bind/2 | Bind parameters to a prepared statement. |
bool_to_int/1 | Convert boolean values into integers (SQlite uses 0 and 1 for boolean values). |
close/1 | Close database connection. |
err_to_atom/1 | Convert an integer error value into the corresponding error atom. |
exec/2 | Evaluate DDL/DML SQL statement(s). |
exec/3 | Evaluate a DDL/DML SQL statement, binding query parameters. |
expand_error/1 | Convert a sqlite3_nif error, if present, into an error atom. |
expand_error/2 | Convert a sqlite3_nif error, if present, into an error atom and error description. |
fetchall/1 | Evaluate a prepared statement and fetch all results. |
fold/4 | Calls Fun(Elem, Acc) on successive elements of the list
formed by evaluating a SQL statement. |
fold/5 | Same as fold/4 but accepts a parameter list. |
insert_many/3 | Insert many values. |
int_to_bool/1 | Convert integer values into booleans (SQlite uses 0 and 1 for boolean values). |
make_flags/1 | Convert a list of atoms into an integer flag. |
map/3 | Transform the result of evaluating a SQL query by applying
Fun(Elem) . |
map/4 | Same as map/4 but accepts a parameter list. |
open/1 | Open a new database connection. |
open/2 | Open a new database connection with the specified open flags. |
open/3 | Open a new database connection with the specified open flags and the VFS engine. |
prepare/2 | Prepare a statement to use with bind/2, step/1, fetchall/1, fetchall2. |
q/2 | Evaluate an SQL expression and fetch all results. |
q/3 | Evaluate an SQL expression, binding the parameters, and fetch all results. |
reset/1 | Reset a prepared statement. |
step/1 | Evaluate a prepared statement and fetch one result. |
with_trxn/2 | Evaluate F in a transaction. |
atom_to_int_flag(X1::atom) -> integer()
Convert an atom into an integer flag.
bind(Stmt, Params) -> Result
Bind parameters to a prepared statement.
bool_to_int(X1::boolean()) -> 0 | 1
Convert boolean values into integers (SQlite uses 0 and 1 for boolean values).
close(Db) -> Result
Close database connection. NOTE: Usually, it is not necessary to call the function because a garbage collection will destroy the connection object. However, it may be useful to have the explicit control over a connection handle in some situations.
err_to_atom(X1::integer()) -> atom()
Convert an integer error value into the corresponding error atom.
exec(Db, Sql) -> Result
Evaluate DDL/DML SQL statement(s).
exec(Db, Sql, Params) -> Result
Evaluate a DDL/DML SQL statement, binding query parameters. NOTE: Using more than one SQL statement with non-empty parameter list will most likely result in an error because the function will try to bind the supplied parameter list to every statement.
expand_error(OK) -> any()
Convert a sqlite3_nif error, if present, into an error atom.
expand_error(Db, OK) -> any()
Convert a sqlite3_nif error, if present, into an error atom and error description.
fetchall(Stmt) -> Result
Evaluate a prepared statement and fetch all results.
fold(Db, Sql, Fun, Acc0) -> Result
Calls Fun(Elem, Acc)
on successive elements of the list
formed by evaluating a SQL statement. Fun/2
must return a new
accumulator, which is passed to the next call. The function returns the
final value of the accumulator or error.
fold(Db, Sql, Params, Fun, Acc0) -> Result
Same as fold/4
but accepts a parameter list.
insert_many(Db, Sql, ParameterList::[Params]) -> Result
Insert many values.
The function prepares an DML SQL statement and binds/evaluates it to every
element in ParameterList
.
int_to_bool(X::integer()) -> boolean()
Convert integer values into booleans (SQlite uses 0 and 1 for boolean values).
make_flags(Atoms::[atom()]) -> integer()
Convert a list of atoms into an integer flag.
map(Db, Sql, Fun) -> Result
Transform the result of evaluating a SQL query by applying
Fun(Elem)
. Returns the transformed list or an error.
map(Db, Sql, Params, Fun) -> Result
Same as map/4
but accepts a parameter list.
open(DbFile) -> Result
Open a new database connection.
open(DbFile, Flags) -> Result
Flags: is a combination of open flags OR
-ed together.
For example ?SQLITE_OPEN_READWRITE bor ?SQLITE_OPEN_CREATE
.
Open a new database connection with the specified open flags.
See also: The list of possible flag values.
open(DbFile, Flags, Vfs) -> Result
Open a new database connection with the specified open flags and the VFS engine. See sqlite3 documentation for details.
prepare(Db, Sql) -> Result
Prepare a statement to use with bind/2, step/1, fetchall/1, fetchall2.
q(Db, Sql) -> Result
Evaluate an SQL expression and fetch all results.
q(Db, Sql, Params) -> Result
Evaluate an SQL expression, binding the parameters, and fetch all results.
reset(Stmt::sqlite3_stmt()) -> sqlite3_error_code()
Reset a prepared statement.
step(Stmt) -> Result
Evaluate a prepared statement and fetch one result. A statement should
be run till ok
is returned.
NOTE: a fully evaluated statement must be reset for re-use in another
operation.
with_trxn(Db, F) -> Result
Evaluate F
in a transaction.
The function automatically rolls back if F
throws an error.
Generated by EDoc