glite
Types
An opaque connection handle backed by an OTP actor.
pub opaque type Connection
A query parameter value.
pub type Param =
value.Value
Values
pub fn connect(
config: config.Config,
) -> Result(Connection, error.Error)
Open a SQLite database and return a connection handle. The connection is managed by an OTP actor process.
pub fn disconnect(conn: Connection) -> Nil
Close the database connection and stop the actor.
pub fn exec(
conn: Connection,
sql: String,
params: List(value.Value),
) -> Result(Int, error.Error)
Execute a statement that does not return rows (CREATE, INSERT, UPDATE, DELETE). Returns the number of rows affected.
pub fn exec_many(
conn: Connection,
sql: String,
params_list: List(List(value.Value)),
) -> Result(Int, error.Error)
Execute a statement many times with different parameter sets. Prepares once, then binds+steps for each param set efficiently. Returns the total number of rows affected.
pub fn nullable(
val: option.Option(a),
to_param: fn(a) -> value.Value,
) -> value.Value
Create a nullable parameter from an Option value.
pub fn query(
conn: Connection,
sql: String,
params: List(value.Value),
) -> Result(connection.QueryResult, error.Error)
Execute a query and return raw results (column names + rows of Values).
pub fn query_one(
conn: Connection,
sql: String,
params: List(value.Value),
decoder: decode.RowDecoder(a),
) -> Result(a, error.Error)
Execute a query and return the first decoded row, or error if no rows.
pub fn query_with(
conn: Connection,
sql: String,
params: List(value.Value),
decoder: decode.RowDecoder(a),
) -> Result(Response(a), error.Error)
Execute a query and decode each row using the provided decoder.
pub fn transaction(
conn: Connection,
f: fn(Connection) -> Result(a, error.Error),
) -> Result(a, error.Error)
Execute a function within a transaction. Automatically BEGINs, and COMMITs on Ok or ROLLBACKs on Error.