glimr_postgres/db/query
PostgreSQL Query Execution
The pog library returns its own error types but the rest of the framework expects DbError. This module bridges that gap — wrapping pog calls so all query errors surface as the framework’s unified DbError type and callers never depend on pog directly.
Types
Aliasing pog.Connection locally lets downstream code reference Connection without importing pog directly, so the driver can be swapped without touching every call site.
pub type Connection =
pog.Connection
Values
pub fn exec(
conn: pog.Connection,
sql: String,
) -> Result(Int, db.DbError)
DDL and write operations still return an affected row count which callers may use for “0 rows updated” checks. Keeping this separate from query avoids forcing callers to supply a decoder they’d never use.
pub fn query(
conn: pog.Connection,
sql: String,
params: List(pog.Value),
decoder: decode.Decoder(t),
) -> Result(List(t), db.DbError)
Thin wrapper so application code can run SELECT queries without importing pog or handling its error types. The decoder is passed through unchanged since pog already supports Gleam decoders natively.
pub fn vtable_exec(
handle: dynamic.Dynamic,
sql: String,
params: List(db.Value),
) -> Result(Int, db.DbError)
Mirrors vtable_query but for write operations that only return an affected row count. The same Dynamic coercion and Value conversion applies so the vtable interface stays consistent across query and exec paths.
pub fn vtable_query(
handle: dynamic.Dynamic,
sql: String,
params: List(db.Value),
decoder: decode.Decoder(a),
) -> Result(db.QueryResult(a), db.DbError)
The framework’s db dispatches through a vtable of Dynamic-typed callbacks so it stays driver-agnostic. This function satisfies that interface by coercing the handle and converting generic Values to pog-specific values before executing.