Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
4.7 kB · 174 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175//// This module contains the code to run the sql queries defined in//// `./src/server/user/sql`.//// > 🐿️ This module was generated automatically using v4.7.0 of//// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).////
import gleam/dynamic/decodeimport gleam/time/timestamp.{type Timestamp}import pogimport youid/uuid.{type Uuid}
/// A row you get from running the `get` query/// defined in `./src/server/user/sql/get.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type GetRow { GetRow( id: Uuid, full_name: String, email: String, created_at: Timestamp, is_active: Bool, )}
/// select an user;////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn get( db: pog.Connection, arg_1: Uuid,) -> Result(pog.Returned(GetRow), pog.QueryError) { let decoder = { use id <- decode.field(0, uuid_decoder()) use full_name <- decode.field(1, decode.string) use email <- decode.field(2, decode.string) use created_at <- decode.field(3, pog.timestamp_decoder()) use is_active <- decode.field(4, decode.bool) decode.success(GetRow(id:, full_name:, email:, created_at:, is_active:)) }
"-- select an user;SELECT u.id, u.full_name, u.email, u.created_at, u.is_activeFROM public.user_account AS uWHERE u.id = $1::uuid;" |> pog.query |> pog.parameter(pog.text(uuid.to_string(arg_1))) |> pog.returning(decoder) |> pog.execute(db)}
/// A row you get from running the `get_credentials` query/// defined in `./src/server/user/sql/get_credentials.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type GetCredentialsRow { GetCredentialsRow(id: Uuid, password_hash: String)}
/// select user id and credentials////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn get_credentials( db: pog.Connection, arg_1: String,) -> Result(pog.Returned(GetCredentialsRow), pog.QueryError) { let decoder = { use id <- decode.field(0, uuid_decoder()) use password_hash <- decode.field(1, decode.string) decode.success(GetCredentialsRow(id:, password_hash:)) }
"-- select user id and credentialsSELECT u.id, u.password_hashFROM public.user_account AS uWHERE u.email = $1::text;" |> pog.query |> pog.parameter(pog.text(arg_1)) |> pog.returning(decoder) |> pog.execute(db)}
/// A row you get from running the `register` query/// defined in `./src/server/user/sql/register.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type RegisterRow { RegisterRow( id: Uuid, full_name: String, email: String, created_at: Timestamp, is_active: Bool, )}
/// register a new user////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn register( db: pog.Connection, arg_1: String, arg_2: String, arg_3: String,) -> Result(pog.Returned(RegisterRow), pog.QueryError) { let decoder = { use id <- decode.field(0, uuid_decoder()) use full_name <- decode.field(1, decode.string) use email <- decode.field(2, decode.string) use created_at <- decode.field(3, pog.timestamp_decoder()) use is_active <- decode.field(4, decode.bool) decode.success(RegisterRow(id:, full_name:, email:, created_at:, is_active:)) }
"-- register a new userINSERT INTO public.user_account AS u ( full_name, email, password_hash )VALUES ($1::text, $2::text, $3::text)RETURNING u.id, u.full_name, u.email, u.created_at, u.is_active;" |> pog.query |> pog.parameter(pog.text(arg_1)) |> pog.parameter(pog.text(arg_2)) |> pog.parameter(pog.text(arg_3)) |> pog.returning(decoder) |> pog.execute(db)}
// --- Encoding/decoding utils -------------------------------------------------
/// A decoder to decode `Uuid`s coming from a Postgres query.///fn uuid_decoder() { use bit_array <- decode.then(decode.bit_array) case uuid.from_bit_array(bit_array) { Ok(uuid) -> decode.success(uuid) Error(_) -> decode.failure(uuid.v7(), "Uuid") }}