glite/tx
Statements inside a transaction.
A transaction’s callback runs in the calling process, holding the
connection, and gets a Tx. Nothing else uses the connection until the
callback returns, so no other caller’s statements can mix into the
transaction. Use only the Tx inside the callback: calling the
Connection from there panics, because the callback holds it.
Once the call’s call_timeout_ms has passed, every statement on the Tx
returns Timeout without running, so a body that keeps going after a
timeout can’t keep the connection busy with more SQL.
Types
Values
pub fn exec(
tx: Tx,
sql: String,
params: List(value.Value),
) -> Result(Int, error.Error)
Run one statement and return the number of rows it changed.
pub fn exec_many(
tx: Tx,
sql: String,
params: List(List(value.Value)),
) -> Result(Int, error.Error)
Run one statement once per parameter list, all or nothing.
pub fn exec_script(
tx: Tx,
sql: String,
) -> Result(Nil, error.Error)
Run a script of several statements, without parameters.
pub fn query(
tx: Tx,
sql: String,
params: List(value.Value),
decoder: decode.RowDecoder(a),
) -> Result(List(a), error.Error)
Run a query and decode every row.
pub fn query_one(
tx: Tx,
sql: String,
params: List(value.Value),
decoder: decode.RowDecoder(a),
) -> Result(a, error.Error)
Run a query that returns exactly one row, and decode it.
pub fn query_rows(
tx: Tx,
sql: String,
params: List(value.Value),
) -> Result(@internal Rows, error.Error)
Run a query and return its column names and raw rows.
pub fn set_user_version(
tx: Tx,
version: Int,
) -> Result(Nil, error.Error)
Set the database’s user_version.
pub fn user_version(tx: Tx) -> Result(Int, error.Error)
The database’s user_version, for schema migrations.