···11+//// This module contains the code to run the sql queries defined in
22+//// `./src/db/sql`.
33+//// > 🐿️ This module was generated automatically using v4.6.0 of
44+//// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
55+////
66+77+import gleam/dynamic/decode
88+import pog
99+1010+/// A row you get from running the `create_account` query
1111+/// defined in `./src/db/sql/create_account.sql`.
1212+///
1313+/// > 🐿️ This type definition was generated automatically using v4.6.0 of the
1414+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
1515+///
1616+pub type CreateAccountRow {
1717+ CreateAccountRow(id: String)
1818+}
1919+2020+/// Runs the `create_account` query
2121+/// defined in `./src/db/sql/create_account.sql`.
2222+///
2323+/// > 🐿️ This function was generated automatically using v4.6.0 of
2424+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
2525+///
2626+pub fn create_account(
2727+ db: pog.Connection,
2828+ arg_1: String,
2929+) -> Result(pog.Returned(CreateAccountRow), pog.QueryError) {
3030+ let decoder = {
3131+ use id <- decode.field(0, decode.string)
3232+ decode.success(CreateAccountRow(id:))
3333+ }
3434+3535+ "INSERT INTO
3636+ accounts (id)
3737+VALUES
3838+ ($1)
3939+ON CONFLICT DO NOTHING
4040+RETURNING
4141+ *
4242+"
4343+ |> pog.query
4444+ |> pog.parameter(pog.text(arg_1))
4545+ |> pog.returning(decoder)
4646+ |> pog.execute(db)
4747+}
4848+4949+/// A row you get from running the `get_account` query
5050+/// defined in `./src/db/sql/get_account.sql`.
5151+///
5252+/// > 🐿️ This type definition was generated automatically using v4.6.0 of the
5353+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
5454+///
5555+pub type GetAccountRow {
5656+ GetAccountRow(id: String)
5757+}
5858+5959+/// Runs the `get_account` query
6060+/// defined in `./src/db/sql/get_account.sql`.
6161+///
6262+/// > 🐿️ This function was generated automatically using v4.6.0 of
6363+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
6464+///
6565+pub fn get_account(
6666+ db: pog.Connection,
6767+ arg_1: String,
6868+) -> Result(pog.Returned(GetAccountRow), pog.QueryError) {
6969+ let decoder = {
7070+ use id <- decode.field(0, decode.string)
7171+ decode.success(GetAccountRow(id:))
7272+ }
7373+7474+ "SELECT
7575+ *
7676+FROM
7777+ accounts
7878+WHERE
7979+ id = $1
8080+"
8181+ |> pog.query
8282+ |> pog.parameter(pog.text(arg_1))
8383+ |> pog.returning(decoder)
8484+ |> pog.execute(db)
8585+}
8686+8787+/// A row you get from running the `get_field_and_tiles_by_id` query
8888+/// defined in `./src/db/sql/get_field_and_tiles_by_id.sql`.
8989+///
9090+/// > 🐿️ This type definition was generated automatically using v4.6.0 of the
9191+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
9292+///
9393+pub type GetFieldAndTilesByIdRow {
9494+ GetFieldAndTilesByIdRow(field: String, field_tiles: String)
9595+}
9696+9797+/// Runs the `get_field_and_tiles_by_id` query
9898+/// defined in `./src/db/sql/get_field_and_tiles_by_id.sql`.
9999+///
100100+/// > 🐿️ This function was generated automatically using v4.6.0 of
101101+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
102102+///
103103+pub fn get_field_and_tiles_by_id(
104104+ db: pog.Connection,
105105+ arg_1: Int,
106106+) -> Result(pog.Returned(GetFieldAndTilesByIdRow), pog.QueryError) {
107107+ let decoder = {
108108+ use field <- decode.field(0, decode.string)
109109+ use field_tiles <- decode.field(1, decode.string)
110110+ decode.success(GetFieldAndTilesByIdRow(field:, field_tiles:))
111111+ }
112112+113113+ "SELECT
114114+ to_json(fields.*) AS field,
115115+ json_arrayagg (field_tiles.* ABSENT ON NULL) AS field_tiles
116116+FROM
117117+ fields
118118+ LEFT JOIN field_tiles ON field_tiles.field_id = fields.id
119119+WHERE
120120+ fields.id = $1
121121+GROUP BY
122122+ fields.id
123123+"
124124+ |> pog.query
125125+ |> pog.parameter(pog.int(arg_1))
126126+ |> pog.returning(decoder)
127127+ |> pog.execute(db)
128128+}
129129+130130+/// A row you get from running the `get_field_by_id` query
131131+/// defined in `./src/db/sql/get_field_by_id.sql`.
132132+///
133133+/// > 🐿️ This type definition was generated automatically using v4.6.0 of the
134134+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
135135+///
136136+pub type GetFieldByIdRow {
137137+ GetFieldByIdRow(id: Int, name: String, account_id: String)
138138+}
139139+140140+/// Runs the `get_field_by_id` query
141141+/// defined in `./src/db/sql/get_field_by_id.sql`.
142142+///
143143+/// > 🐿️ This function was generated automatically using v4.6.0 of
144144+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
145145+///
146146+pub fn get_field_by_id(
147147+ db: pog.Connection,
148148+ arg_1: Int,
149149+) -> Result(pog.Returned(GetFieldByIdRow), pog.QueryError) {
150150+ let decoder = {
151151+ use id <- decode.field(0, decode.int)
152152+ use name <- decode.field(1, decode.string)
153153+ use account_id <- decode.field(2, decode.string)
154154+ decode.success(GetFieldByIdRow(id:, name:, account_id:))
155155+ }
156156+157157+ "SELECT
158158+ *
159159+FROM
160160+ fields
161161+WHERE
162162+ id = $1
163163+"
164164+ |> pog.query
165165+ |> pog.parameter(pog.int(arg_1))
166166+ |> pog.returning(decoder)
167167+ |> pog.execute(db)
168168+}
169169+170170+/// A row you get from running the `list_fields_for_account` query
171171+/// defined in `./src/db/sql/list_fields_for_account.sql`.
172172+///
173173+/// > 🐿️ This type definition was generated automatically using v4.6.0 of the
174174+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
175175+///
176176+pub type ListFieldsForAccountRow {
177177+ ListFieldsForAccountRow(id: Int, name: String, account_id: String)
178178+}
179179+180180+/// Runs the `list_fields_for_account` query
181181+/// defined in `./src/db/sql/list_fields_for_account.sql`.
182182+///
183183+/// > 🐿️ This function was generated automatically using v4.6.0 of
184184+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
185185+///
186186+pub fn list_fields_for_account(
187187+ db: pog.Connection,
188188+ arg_1: String,
189189+) -> Result(pog.Returned(ListFieldsForAccountRow), pog.QueryError) {
190190+ let decoder = {
191191+ use id <- decode.field(0, decode.int)
192192+ use name <- decode.field(1, decode.string)
193193+ use account_id <- decode.field(2, decode.string)
194194+ decode.success(ListFieldsForAccountRow(id:, name:, account_id:))
195195+ }
196196+197197+ "SELECT
198198+ *
199199+FROM
200200+ fields
201201+WHERE
202202+ account_id = $1
203203+"
204204+ |> pog.query
205205+ |> pog.parameter(pog.text(arg_1))
206206+ |> pog.returning(decoder)
207207+ |> pog.execute(db)
208208+}
+7
server/src/db/sql/create_account.sql
···11+INSERT INTO
22+ accounts (id)
33+VALUES
44+ ($1)
55+ON CONFLICT DO NOTHING
66+RETURNING
77+ *