glite

Types

An opaque connection handle backed by an OTP actor.

pub opaque type Connection

A query parameter value.

pub type Param =
  value.Value

Result from a decoded query.

pub type Response(a) {
  Response(rows: List(a), count: Int)
}

Constructors

  • Response(rows: List(a), count: Int)

Values

pub fn blob(val: BitArray) -> value.Value

Create a blob (binary data) parameter.

pub fn bool(val: Bool) -> value.Value

Create a boolean parameter (stored as Integer 0/1).

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 float(val: Float) -> value.Value

Create a float parameter.

pub fn int(val: Int) -> value.Value

Create an integer parameter.

pub fn last_insert_rowid(conn: Connection) -> Int

Get the last insert rowid.

pub fn null() -> value.Value

Create a NULL parameter.

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 text(val: String) -> value.Value

Create a text/string parameter.

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.

Search Document