gloo/repo

Execute queries against a database connection pool.

Functions accept either a Query(t) (from the query builder), a Sql(t) (from the sql module), or a plain SQL string + params list.

Transaction semantics: Ok commits, Error rolls back. Nested repo.transaction calls automatically become savepoints.

Types

pub opaque type Repo

Values

pub fn all(
  repo: Repo,
  sql: String,
  params: List(value.GlooValue),
  decoder: decode.Decoder(t),
) -> Result(List(t), error.GlooError)
pub fn close(repo: Repo) -> Result(Nil, String)

Close the underlying DB connection. For Postgres this is a no-op (pog manages the pool lifecycle). For SQLite this closes the file.

pub fn execute(
  repo: Repo,
  sql: String,
  params: List(value.GlooValue),
) -> Result(Int, error.GlooError)
pub fn from_adapter(adapter: adapter.Adapter) -> Repo
pub fn maybe_one(
  repo: Repo,
  sql: String,
  params: List(value.GlooValue),
  decoder: decode.Decoder(t),
) -> Result(option.Option(t), error.GlooError)
pub fn maybe_one_from_rows(
  rows: List(t),
) -> Result(option.Option(t), error.GlooError)
pub fn one(
  repo: Repo,
  sql: String,
  params: List(value.GlooValue),
  decoder: decode.Decoder(t),
) -> Result(t, error.GlooError)
pub fn one_from_rows(rows: List(t)) -> Result(t, error.GlooError)
pub fn query_all(
  repo: Repo,
  q: query.Query(t),
) -> Result(List(t), error.GlooError)
pub fn query_execute(
  repo: Repo,
  q: query.Query(t),
) -> Result(Int, error.GlooError)
pub fn query_maybe_one(
  repo: Repo,
  q: query.Query(t),
) -> Result(option.Option(t), error.GlooError)
pub fn query_one(
  repo: Repo,
  q: query.Query(t),
) -> Result(t, error.GlooError)
pub fn sql_all(
  repo: Repo,
  s: sql.Sql(t),
) -> Result(List(t), error.GlooError)
pub fn sql_execute(
  repo: Repo,
  s: sql.Sql(t),
) -> Result(Int, error.GlooError)
pub fn sql_maybe_one(
  repo: Repo,
  s: sql.Sql(t),
) -> Result(option.Option(t), error.GlooError)
pub fn sql_one(
  repo: Repo,
  s: sql.Sql(t),
) -> Result(t, error.GlooError)
pub fn transaction(
  repo: Repo,
  callback: fn(Repo) -> Result(t, error.GlooError),
) -> Result(t, error.GlooError)

V5: Ok → commit, Error → rollback. V6: nested calls become savepoints (savepoint_depth > 0).

pub fn with_telemetry(repo: Repo, t: telemetry.Telemetry) -> Repo
Search Document