Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
15 kB · 565 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566//// This module contains the code to run the sql queries defined in//// `./src/server/startup/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 `assign_expertise` query/// defined in `./src/server/startup/sql/assign_expertise.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type AssignExpertiseRow { AssignExpertiseRow(expertise_id: Uuid)}
/// Assign an expertise to a startup////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn assign_expertise( db: pog.Connection, arg_1: Uuid, arg_2: Uuid,) -> Result(pog.Returned(AssignExpertiseRow), pog.QueryError) { let decoder = { use expertise_id <- decode.field(0, uuid_decoder()) decode.success(AssignExpertiseRow(expertise_id:)) }
"-- Assign an expertise to a startupINSERT INTO public.startup_expertise (startup_id, expertise_id)SELECT $1::uuid AS startup_id, $2::uuid AS expertise_idRETURNING expertise_id;" |> pog.query |> pog.parameter(pog.text(uuid.to_string(arg_1))) |> pog.parameter(pog.text(uuid.to_string(arg_2))) |> pog.returning(decoder) |> pog.execute(db)}
/// A row you get from running the `assign_member` query/// defined in `./src/server/startup/sql/assign_member.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type AssignMemberRow { AssignMemberRow(user_id: Uuid)}
/// Assign members to a startup////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn assign_member( db: pog.Connection, arg_1: Uuid, arg_2: Uuid,) -> Result(pog.Returned(AssignMemberRow), pog.QueryError) { let decoder = { use user_id <- decode.field(0, uuid_decoder()) decode.success(AssignMemberRow(user_id:)) }
"-- Assign members to a startupINSERT INTO public.startup_membership (startup_id, user_id)SELECT $1::uuid AS startup_id, $2::uuid AS user_idRETURNING user_id;" |> pog.query |> pog.parameter(pog.text(uuid.to_string(arg_1))) |> pog.parameter(pog.text(uuid.to_string(arg_2))) |> pog.returning(decoder) |> pog.execute(db)}
/// A row you get from running the `assign_segment` query/// defined in `./src/server/startup/sql/assign_segment.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type AssignSegmentRow { AssignSegmentRow(segment_id: Uuid)}
/// assign a given Segment to a Startup////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn assign_segment( db: pog.Connection, arg_1: Uuid, arg_2: Uuid, arg_3: Bool,) -> Result(pog.Returned(AssignSegmentRow), pog.QueryError) { let decoder = { use segment_id <- decode.field(0, uuid_decoder()) decode.success(AssignSegmentRow(segment_id:)) }
"-- assign a given Segment to a StartupINSERT INTO public.startup_segment (startup_id, segment_id, is_main_segment)SELECT $1::uuid AS startup_id, $2::uuid AS segment_id, $3::boolean AS is_main_segmentRETURNING segment_id;" |> pog.query |> pog.parameter(pog.text(uuid.to_string(arg_1))) |> pog.parameter(pog.text(uuid.to_string(arg_2))) |> pog.parameter(pog.bool(arg_3)) |> pog.returning(decoder) |> pog.execute(db)}
/// A row you get from running the `assign_service` query/// defined in `./src/server/startup/sql/assign_service.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type AssignServiceRow { AssignServiceRow(service_id: Uuid)}
/// Assign a service to a Startup////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn assign_service( db: pog.Connection, arg_1: Uuid, arg_2: Uuid,) -> Result(pog.Returned(AssignServiceRow), pog.QueryError) { let decoder = { use service_id <- decode.field(0, uuid_decoder()) decode.success(AssignServiceRow(service_id:)) }
"-- Assign a service to a StartupINSERT INTO public.startup_service (startup_id, service_id)SELECT $1::uuid AS startup_id, $2::uuid AS service_idRETURNING service_id;" |> pog.query |> pog.parameter(pog.text(uuid.to_string(arg_1))) |> pog.parameter(pog.text(uuid.to_string(arg_2))) |> pog.returning(decoder) |> pog.execute(db)}
/// A row you get from running the `ensure_exists` query/// defined in `./src/server/startup/sql/ensure_exists.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type EnsureExistsRow { EnsureExistsRow(found: Int)}
/// return a single column if the given startup exists////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn ensure_exists( db: pog.Connection, arg_1: Uuid,) -> Result(pog.Returned(EnsureExistsRow), pog.QueryError) { let decoder = { use found <- decode.field(0, decode.int) decode.success(EnsureExistsRow(found:)) }
"-- return a single column if the given startup existsSELECT 1 AS foundFROM startup AS sWHERE s.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` query/// defined in `./src/server/startup/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, name: String, stage: StartupStage, cnpj: String, description: String, city: String, state: String, created_at: Timestamp, )}
/// select an startup;////// > 🐿️ 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 name <- decode.field(1, decode.string) use stage <- decode.field(2, startup_stage_decoder()) use cnpj <- decode.field(3, decode.string) use description <- decode.field(4, decode.string) use city <- decode.field(5, decode.string) use state <- decode.field(6, decode.string) use created_at <- decode.field(7, pog.timestamp_decoder()) decode.success(GetRow( id:, name:, stage:, cnpj:, description:, city:, state:, created_at:, )) }
"-- select an startup;SELECT s.id, s.name, s.stage, s.cnpj, s.description, s.city, s.state, s.created_atFROM public.startup AS sWHERE s.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_expertises` query/// defined in `./src/server/startup/sql/get_expertises.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type GetExpertisesRow { GetExpertisesRow(id: Uuid, name: String, description: String)}
/// get all expertises that a given startup is assigned to////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn get_expertises( db: pog.Connection, arg_1: Uuid,) -> Result(pog.Returned(GetExpertisesRow), pog.QueryError) { let decoder = { use id <- decode.field(0, uuid_decoder()) use name <- decode.field(1, decode.string) use description <- decode.field(2, decode.string) decode.success(GetExpertisesRow(id:, name:, description:)) }
"-- get all expertises that a given startup is assigned toSELECT e.id, e.name, e.descriptionFROM public.expertise AS e INNER JOIN public.startup_expertise AS se ON se.expertise_id = e.idWHERE se.startup_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_members` query/// defined in `./src/server/startup/sql/get_members.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type GetMembersRow { GetMembersRow( id: Uuid, full_name: String, email: String, created_at: Timestamp, is_active: Bool, )}
/// get all members assigned to a given startup////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn get_members( db: pog.Connection, arg_1: Uuid,) -> Result(pog.Returned(GetMembersRow), 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(GetMembersRow( id:, full_name:, email:, created_at:, is_active:, )) }
"-- get all members assigned to a given startupSELECT u.id, u.full_name, u.email, u.created_at, u.is_activeFROM public.user_account AS u INNER JOIN public.startup_membership AS sm ON sm.user_id = u.idWHERE sm.startup_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_segments` query/// defined in `./src/server/startup/sql/get_segments.sql`.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type GetSegmentsRow { GetSegmentsRow(id: Uuid, name: String, description: String)}
/// select all segments from a startup////// > 🐿️ This function was generated automatically using v4.7.0 of/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub fn get_segments( db: pog.Connection, arg_1: Uuid,) -> Result(pog.Returned(GetSegmentsRow), pog.QueryError) { let decoder = { use id <- decode.field(0, uuid_decoder()) use name <- decode.field(1, decode.string) use description <- decode.field(2, decode.string) decode.success(GetSegmentsRow(id:, name:, description:)) }
"-- select all segments from a startupSELECT s.id, s.name, s.descriptionFROM segment AS s INNER JOIN startup_segment AS ss ON ss.segment_id = s.idWHERE ss.startup_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 `register` query/// defined in `./src/server/startup/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, name: String, stage: StartupStage, cnpj: String, description: String, city: String, state: String, created_at: Timestamp, )}
/// register a new startup on the database////// > 🐿️ 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: StartupStage, arg_3: String, arg_4: String, arg_5: String, arg_6: String,) -> Result(pog.Returned(RegisterRow), pog.QueryError) { let decoder = { use id <- decode.field(0, uuid_decoder()) use name <- decode.field(1, decode.string) use stage <- decode.field(2, startup_stage_decoder()) use cnpj <- decode.field(3, decode.string) use description <- decode.field(4, decode.string) use city <- decode.field(5, decode.string) use state <- decode.field(6, decode.string) use created_at <- decode.field(7, pog.timestamp_decoder()) decode.success(RegisterRow( id:, name:, stage:, cnpj:, description:, city:, state:, created_at:, )) }
"-- register a new startup on the databaseINSERT INTO public.startup ( name, stage, cnpj, description, city, state )VALUES ( $1::text, $2::startup_stage, $3::text, $4::text, $5::text, $6::text )RETURNING id, name, stage, cnpj, description, city, state, created_at;" |> pog.query |> pog.parameter(pog.text(arg_1)) |> pog.parameter(startup_stage_encoder(arg_2)) |> pog.parameter(pog.text(arg_3)) |> pog.parameter(pog.text(arg_4)) |> pog.parameter(pog.text(arg_5)) |> pog.parameter(pog.text(arg_6)) |> pog.returning(decoder) |> pog.execute(db)}
// --- Enums -------------------------------------------------------------------
/// Corresponds to the Postgres `startup_stage` enum.////// > 🐿️ This type definition was generated automatically using v4.7.0 of the/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).///pub type StartupStage { Growth Seed}
fn startup_stage_decoder() -> decode.Decoder(StartupStage) { use startup_stage <- decode.then(decode.string) case startup_stage { "growth" -> decode.success(Growth) "seed" -> decode.success(Seed) _ -> decode.failure(Growth, "StartupStage") }}
fn startup_stage_encoder(startup_stage) -> pog.Value { case startup_stage { Growth -> "growth" Seed -> "seed" } |> pog.text}
// --- 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") }}