gloo/sql
Typed raw SQL builder. Use when a query spans multiple tables or needs features the query builder does not cover.
sql.query("SELECT * FROM users WHERE id = $1")
|> sql.param(sql.int(id))
|> sql.returns(user_decoder)
|> repo.sql_one(r, _)
Value constructors: string, int, bool, time, uuid, nullable.
A Sql(t) value is inert until passed to a repo.sql_* function.
Types
Values
pub fn bool(v: Bool) -> value.GlooValue
pub fn in_clause(
sql: Sql(t),
values: List(value.GlooValue),
) -> #(Sql(t), String)
Generates ($n, $n+1, ...) for use in an IN clause.
Returns the placeholder fragment and the updated Sql with params added.
pub fn int(v: Int) -> value.GlooValue
pub fn nullable(
encoder: fn(a) -> value.GlooValue,
v: option.Option(a),
) -> value.GlooValue
pub fn param(sql: Sql(t), v: value.GlooValue) -> Sql(t)
pub fn params(
sql: Sql(t),
values: List(value.GlooValue),
) -> Sql(t)
pub fn returns(sql: Sql(t), decoder: decode.Decoder(u)) -> Sql(u)
pub fn string(v: String) -> value.GlooValue
pub fn time(v: birl.Time) -> value.GlooValue
pub fn to_parts(
sql: Sql(t),
) -> #(String, List(value.GlooValue), decode.Decoder(t))
pub fn unnest(
encoder: fn(a) -> value.GlooValue,
values: List(a),
) -> value.GlooValue
Encodes a list as a Postgres array for use with UNNEST (Postgres-only).
pub fn uuid(v: String) -> value.GlooValue