wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:art: lowercase squirrel generated functions

Kacaii 49f753a5 4d9ec135

+170 -170
+4 -4
dev/app_dev/sql.gleam
··· 18 18 ) -> Result(pog.Returned(Nil), pog.QueryError) { 19 19 let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 20 20 21 - "DELETE FROM public.user_account 22 - WHERE registration != '000'; 21 + "delete from public.user_account 22 + where registration != '000'; 23 23 " 24 24 |> pog.query 25 25 |> pog.returning(decoder) ··· 37 37 ) -> Result(pog.Returned(Nil), pog.QueryError) { 38 38 let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 39 39 40 - "TRUNCATE TABLE public.brigade CASCADE; 40 + "truncate table public.brigade cascade; 41 41 " 42 42 |> pog.query 43 43 |> pog.returning(decoder) ··· 55 55 ) -> Result(pog.Returned(Nil), pog.QueryError) { 56 56 let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 57 57 58 - "TRUNCATE TABLE public.occurrence CASCADE; 58 + "truncate table public.occurrence cascade; 59 59 " 60 60 |> pog.query 61 61 |> pog.returning(decoder)
+7 -7
src/app/domain/admin/sql.gleam
··· 61 61 } 62 62 63 63 "--  Update an user's information as admin 64 - UPDATE public.user_account AS u 65 - SET 64 + update public.user_account as u 65 + set 66 66 full_name = $2, 67 67 email = $3, 68 68 user_role = $4, 69 69 registration = $5, 70 70 is_active = $6, 71 - updated_at = CURRENT_TIMESTAMP 72 - WHERE u.id = $1 73 - RETURNING 71 + updated_at = current_timestamp 72 + where u.id = $1 73 + returning 74 74 u.id, 75 75 u.full_name, 76 76 u.email, ··· 114 114 } 115 115 116 116 "-- 󰆙 Count the total number of users in our system 117 - SELECT COUNT(u.id) AS total 118 - FROM public.user_account AS u; 117 + select count(u.id) as total 118 + from public.user_account as u; 119 119 " 120 120 |> pog.query 121 121 |> pog.returning(decoder)
+36 -36
src/app/domain/brigade/sql.gleam
··· 36 36 } 37 37 38 38 "--  Assign a list of members to a brigade 39 - SELECT b.inserted_user_id 40 - FROM public.assign_brigade_members($1, $2) AS b; 39 + select b.inserted_user_id 40 + from public.assign_brigade_members($1, $2) as b; 41 41 " 42 42 |> pog.query 43 43 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 74 74 } 75 75 76 76 "--  Remove a brigade from the DataBase 77 - DELETE FROM public.brigade AS b 78 - WHERE b.id = $1 79 - RETURNING 77 + delete from public.brigade as b 78 + where b.id = $1 79 + returning 80 80 b.id, 81 81 b.brigade_name; 82 82 " ··· 115 115 } 116 116 117 117 "--  Register a new brigade into the database 118 - INSERT INTO public.brigade AS b ( 118 + insert into public.brigade as b ( 119 119 leader_id, 120 120 brigade_name, 121 121 vehicle_code, 122 122 is_active 123 - ) VALUES ( 123 + ) values ( 124 124 $1, 125 125 $2, 126 126 $3, 127 127 $4 128 - ) RETURNING 128 + ) returning 129 129 b.id, 130 130 b.created_at; 131 131 " ··· 175 175 } 176 176 177 177 "-- 󱉯 Find all registered brigades 178 - SELECT 178 + select 179 179 b.id, 180 180 b.brigade_name, 181 - u.full_name AS leader_name, 181 + u.full_name as leader_name, 182 182 b.is_active 183 - FROM public.brigade AS b 184 - LEFT JOIN public.user_account AS u 185 - ON b.leader_id = u.id; 183 + from public.brigade as b 184 + left join public.user_account as u 185 + on b.leader_id = u.id; 186 186 " 187 187 |> pog.query 188 188 |> pog.returning(decoder) ··· 227 227 } 228 228 229 229 "-- 󰡦 Find details about a specific brigade 230 - SELECT 230 + select 231 231 b.id, 232 232 b.brigade_name, 233 - u.id AS leader_name, 233 + u.id as leader_name, 234 234 b.is_active 235 - FROM public.brigade AS b 236 - INNER JOIN public.user_account AS u 237 - ON b.leader_id = u.id 238 - WHERE b.id = $1; 235 + from public.brigade as b 236 + inner join public.user_account as u 237 + on b.leader_id = u.id 238 + where b.id = $1; 239 239 " 240 240 |> pog.query 241 241 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 268 268 } 269 269 270 270 "--  Find the id of all members assigned a specific brigade 271 - SELECT u.id 272 - FROM public.user_account AS u 273 - INNER JOIN public.brigade_membership AS bm 274 - ON u.id = bm.user_id 275 - WHERE bm.brigade_id = $1; 271 + select u.id 272 + from public.user_account as u 273 + inner join public.brigade_membership as bm 274 + on u.id = bm.user_id 275 + where bm.brigade_id = $1; 276 276 " 277 277 |> pog.query 278 278 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 307 307 } 308 308 309 309 "--  Find all members of a brigade 310 - SELECT 310 + select 311 311 u.id, 312 312 u.full_name, 313 313 u.user_role 314 - FROM public.user_account AS u 315 - INNER JOIN public.brigade_membership AS bm 316 - ON u.id = bm.user_id 317 - WHERE bm.brigade_id = $1; 314 + from public.user_account as u 315 + inner join public.brigade_membership as bm 316 + on u.id = bm.user_id 317 + where bm.brigade_id = $1; 318 318 " 319 319 |> pog.query 320 320 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 348 348 } 349 349 350 350 "--  Replace all brigade members 351 - SELECT b.inserted_user_id 352 - FROM public.replace_brigade_members($1, $2) AS b; 351 + select b.inserted_user_id 352 + from public.replace_brigade_members($1, $2) as b; 353 353 " 354 354 |> pog.query 355 355 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 388 388 } 389 389 390 390 "--  Set the brigade is_active status to ON or OFF 391 - UPDATE public.brigade AS b 392 - SET 391 + update public.brigade as b 392 + set 393 393 is_active = $2, 394 - updated_at = CURRENT_TIMESTAMP 395 - WHERE b.id = $1 396 - RETURNING 394 + updated_at = current_timestamp 395 + where b.id = $1 396 + returning 397 397 b.id, 398 398 b.is_active, 399 399 b.updated_at;
+9 -9
src/app/domain/dashboard/sql.gleam
··· 44 44 } 45 45 46 46 "-- 󱘟 Retrieve stats for the Dashboard page 47 - SELECT 48 - (SELECT count FROM public.vw_count_active_brigades) 49 - AS active_brigades_count, 50 - (SELECT count FROM public.vw_count_total_occurrences) 51 - AS total_occurrences_count, 52 - (SELECT count FROM public.vw_count_active_occurrences) 53 - AS active_occurrences_count, 54 - (SELECT count FROM public.vw_count_recent_occurrences) 55 - AS recent_occurrences_count; 47 + select 48 + (select count from public.vw_count_active_brigades) 49 + as active_brigades_count, 50 + (select count from public.vw_count_total_occurrences) 51 + as total_occurrences_count, 52 + (select count from public.vw_count_active_occurrences) 53 + as active_occurrences_count, 54 + (select count from public.vw_count_recent_occurrences) 55 + as recent_occurrences_count; 56 56 " 57 57 |> pog.query 58 58 |> pog.returning(decoder)
+13 -13
src/app/domain/notification/sql.gleam
··· 33 33 } 34 34 35 35 "--  Find the active notifications from an user 36 - SELECT np.notification_type 37 - FROM public.user_notification_preference AS np 38 - WHERE 36 + select np.notification_type 37 + from public.user_notification_preference as np 38 + where 39 39 np.user_id = $1 40 - AND np.enabled = TRUE; 40 + and np.enabled = true; 41 41 " 42 42 |> pog.query 43 43 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 74 74 } 75 75 76 76 "--  Find the notification preferences for an user 77 - SELECT 77 + select 78 78 np.notification_type, 79 79 np.enabled 80 - FROM public.user_notification_preference AS np 81 - WHERE np.user_id = $1; 80 + from public.user_notification_preference as np 81 + where np.user_id = $1; 82 82 " 83 83 |> pog.query 84 84 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 120 120 } 121 121 122 122 "--  Update user notification preference 123 - UPDATE public.user_notification_preference AS np 124 - SET 123 + update public.user_notification_preference as np 124 + set 125 125 enabled = $3, 126 - updated_at = CURRENT_TIMESTAMP 127 - WHERE 126 + updated_at = current_timestamp 127 + where 128 128 np.user_id = $1 129 - AND np.notification_type = $2 130 - RETURNING 129 + and np.notification_type = $2 130 + returning 131 131 new.notification_type, 132 132 new.enabled; 133 133 "
+47 -47
src/app/domain/occurrence/sql.gleam
··· 36 36 } 37 37 38 38 "--  Assign as list of brigades as participants of a occurrence 39 - SELECT ob.inserted_brigade_id 40 - FROM public.assign_occurrence_brigades($1, $2) AS ob; 39 + select ob.inserted_brigade_id 40 + from public.assign_occurrence_brigades($1, $2) as ob; 41 41 " 42 42 |> pog.query 43 43 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 73 73 } 74 74 75 75 "--  Remove an occurrence from the database 76 - DELETE FROM public.occurrence AS o 77 - WHERE o.id = $1 78 - RETURNING o.id; 76 + delete from public.occurrence as o 77 + where o.id = $1 78 + returning o.id; 79 79 " 80 80 |> pog.query 81 81 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 133 133 } 134 134 135 135 "--  Inserts a new occurrence into the database 136 - INSERT INTO public.occurrence AS o ( 136 + insert into public.occurrence as o ( 137 137 applicant_id, 138 138 occurrence_category, 139 139 occurrence_subcategory, ··· 141 141 description, 142 142 occurrence_location, 143 143 reference_point 144 - ) VALUES ( 144 + ) values ( 145 145 $1, 146 146 $2, 147 147 $3, ··· 150 150 $6, 151 151 $7 152 152 ) 153 - RETURNING 153 + returning 154 154 o.id, 155 155 o.occurrence_category, 156 156 o.priority, ··· 239 239 240 240 "--  Retrieves all occurrences associated with a user, 241 241 -- including detailed category information and resolution status. 242 - SELECT 242 + select 243 243 o.id, 244 244 o.resolved_at, 245 245 o.priority, 246 246 o.occurrence_category, 247 247 o.occurrence_location, 248 - o.description AS details, 249 - u.full_name AS applicant_name, 248 + o.description as details, 249 + u.full_name as applicant_name, 250 250 o.created_at, 251 251 o.arrived_at, 252 - u.registration AS applicant_registration, 252 + u.registration as applicant_registration, 253 253 o.applicant_id, 254 254 255 255 ( 256 - SELECT JSON_AGG(JSON_BUILD_OBJECT( 256 + select json_agg(json_build_object( 257 257 'id', b.id, 258 258 'brigade_name', b.brigade_name, 259 259 'leader_full_name', leader_u.full_name, 260 260 'vehicle_code', b.vehicle_code 261 - )) FROM public.occurrence_brigade AS ob 262 - INNER JOIN public.brigade AS b 263 - ON ob.brigade_id = b.id 264 - INNER JOIN public.user_account AS leader_u 265 - ON b.leader_id = leader_u.id 266 - WHERE ob.occurrence_id = o.id 267 - ) AS brigade_list 261 + )) from public.occurrence_brigade as ob 262 + inner join public.brigade as b 263 + on ob.brigade_id = b.id 264 + inner join public.user_account as leader_u 265 + on b.leader_id = leader_u.id 266 + where ob.occurrence_id = o.id 267 + ) as brigade_list 268 268 269 - FROM public.occurrence AS o 270 - INNER JOIN public.user_account AS u 271 - ON o.applicant_id = u.id 272 - WHERE o.applicant_id = $1; 269 + from public.occurrence as o 270 + inner join public.user_account as u 271 + on o.applicant_id = u.id 272 + where o.applicant_id = $1; 273 273 " 274 274 |> pog.query 275 275 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 302 302 } 303 303 304 304 "-- 󰀖 Find all users that participated in a occurrence 305 - SELECT DISTINCT participant.user_id 306 - FROM public.brigade_membership AS participant 307 - INNER JOIN public.occurrence_brigade AS ob 308 - ON participant.brigade_id = ob.brigade_id 309 - WHERE ob.occurrence_id = $1 310 - ORDER BY participant.user_id; 305 + select distinct participant.user_id 306 + from public.brigade_membership as participant 307 + inner join public.occurrence_brigade as ob 308 + on participant.brigade_id = ob.brigade_id 309 + where ob.occurrence_id = $1 310 + order by participant.user_id; 311 311 " 312 312 |> pog.query 313 313 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 370 370 } 371 371 372 372 "--  Find all occurrences from the last 24 hours 373 - SELECT 373 + select 374 374 o.id, 375 375 o.created_at, 376 376 o.description, ··· 378 378 o.occurrence_subcategory, 379 379 o.occurrence_location, 380 380 o.reference_point 381 - FROM public.occurrence AS o 382 - WHERE o.created_at >= (NOW() - '1 day'::INTERVAL); 381 + from public.occurrence as o 382 + where o.created_at >= (now() - '1 day'::interval); 383 383 " 384 384 |> pog.query 385 385 |> pog.returning(decoder) ··· 417 417 } 418 418 419 419 "-- 󰚰 Mark a occurrence as unresolved 420 - UPDATE public.occurrence 421 - SET 422 - resolved_at = NULL, 423 - updated_at = CURRENT_TIMESTAMP 424 - WHERE id = $1 425 - RETURNING 420 + update public.occurrence 421 + set 422 + resolved_at = null, 423 + updated_at = current_timestamp 424 + where id = $1 425 + returning 426 426 id, 427 427 resolved_at, 428 428 updated_at; ··· 459 459 } 460 460 461 461 "--  Replace all assigned brigades 462 - SELECT o.inserted_brigade_id 463 - FROM public.assign_occurrence_brigades($1, $2) AS o; 462 + select o.inserted_brigade_id 463 + from public.assign_occurrence_brigades($1, $2) as o; 464 464 " 465 465 |> pog.query 466 466 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 502 502 } 503 503 504 504 "-- 󰚰 Mark a occurrence as resolved 505 - UPDATE public.occurrence 506 - SET 507 - resolved_at = CURRENT_TIMESTAMP, 508 - updated_at = CURRENT_TIMESTAMP 509 - WHERE id = $1 510 - RETURNING 505 + update public.occurrence 506 + set 507 + resolved_at = current_timestamp, 508 + updated_at = current_timestamp 509 + where id = $1 510 + returning 511 511 id, 512 512 resolved_at, 513 513 updated_at;
+1 -1
src/app/domain/role/sql.gleam
··· 31 31 } 32 32 33 33 "--  Find all available user roles 34 - SELECT UNNEST(ENUM_RANGE(NULL::public.USER_ROLE_ENUM)) AS available_role; 34 + select unnest(enum_range(null::public.user_role_enum)) as available_role; 35 35 " 36 36 |> pog.query 37 37 |> pog.returning(decoder)
+53 -53
src/app/domain/user/sql.gleam
··· 35 35 } 36 36 37 37 "--  Remove and user from the database 38 - DELETE FROM public.user_account AS u 39 - WHERE u.id = $1 40 - RETURNING u.id, u.full_name; 38 + delete from public.user_account as u 39 + where u.id = $1 40 + returning u.id, u.full_name; 41 41 " 42 42 |> pog.query 43 43 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 88 88 } 89 89 90 90 "-- 󰀖 Find all users on the database 91 - SELECT 91 + select 92 92 u.id, 93 93 u.full_name, 94 94 u.registration, 95 95 u.email, 96 96 u.user_role, 97 97 u.is_active 98 - FROM public.user_account AS u; 98 + from public.user_account as u; 99 99 " 100 100 |> pog.query 101 101 |> pog.returning(decoder) ··· 132 132 } 133 133 134 134 "--  Inserts a new user into the database 135 - INSERT INTO public.user_account AS u 135 + insert into public.user_account as u 136 136 ( 137 137 full_name, 138 138 registration, ··· 141 141 password_hash, 142 142 user_role 143 143 ) 144 - VALUES ($1, $2, $3, $4, $5, $6) 145 - RETURNING u.id; 144 + values ($1, $2, $3, $4, $5, $6) 145 + returning u.id; 146 146 " 147 147 |> pog.query 148 148 |> pog.parameter(pog.text(arg_1)) ··· 190 190 191 191 "-- 󰢫 Retrieves detailed information about fellow brigade members 192 192 -- for a given user, including their names and role details. 193 - SELECT 193 + select 194 194 u.id, 195 195 u.full_name, 196 196 u.user_role, 197 197 crew.brigade_id 198 - FROM public.query_crew_members($1) AS crew 199 - INNER JOIN public.user_account AS u 200 - ON crew.member_id = u.id; 198 + from public.query_crew_members($1) as crew 199 + inner join public.user_account as u 200 + on crew.member_id = u.id; 201 201 " 202 202 |> pog.query 203 203 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 234 234 235 235 "--  Retrieves a user's ID and password hash from their registration 236 236 -- number for authentication purposes. 237 - SELECT 237 + select 238 238 u.id, 239 239 u.password_hash, 240 240 u.user_role 241 - FROM public.user_account AS u 242 - WHERE u.registration = $1; 241 + from public.user_account as u 242 + where u.registration = $1; 243 243 " 244 244 |> pog.query 245 245 |> pog.parameter(pog.text(arg_1)) ··· 272 272 } 273 273 274 274 "-- 󰡦 Find all occurrences a user participated in 275 - SELECT u.id 276 - FROM public.user_account AS u 277 - INNER JOIN public.brigade_membership AS bm 278 - ON u.id = bm.user_id 279 - INNER JOIN public.occurrence_brigade AS ob 280 - ON bm.brigade_id = ob.brigade_id 281 - WHERE ob.occurrence_id = $1; 275 + select u.id 276 + from public.user_account as u 277 + inner join public.brigade_membership as bm 278 + on u.id = bm.user_id 279 + inner join public.occurrence_brigade as ob 280 + on bm.brigade_id = ob.brigade_id 281 + where ob.occurrence_id = $1; 282 282 " 283 283 |> pog.query 284 284 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 311 311 } 312 312 313 313 "--  Find all brigades an user is assigned to 314 - SELECT bm.brigade_id 315 - FROM public.brigade_membership AS bm 316 - WHERE bm.user_id = $1; 314 + select bm.brigade_id 315 + from public.brigade_membership as bm 316 + where bm.user_id = $1; 317 317 " 318 318 |> pog.query 319 319 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 346 346 } 347 347 348 348 "--  Retrieves a user's ID from their registration number. 349 - SELECT u.id 350 - FROM public.user_account AS u 351 - WHERE u.registration = $1; 349 + select u.id 350 + from public.user_account as u 351 + where u.registration = $1; 352 352 " 353 353 |> pog.query 354 354 |> pog.parameter(pog.text(arg_1)) ··· 381 381 } 382 382 383 383 "--  Retrieves a user's full name by their user ID. 384 - SELECT u.full_name 385 - FROM public.user_account AS u 386 - WHERE u.id = $1; 384 + select u.full_name 385 + from public.user_account as u 386 + where u.id = $1; 387 387 " 388 388 |> pog.query 389 389 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 416 416 } 417 417 418 418 "--  Find the password hash from an user 419 - SELECT u.password_hash 420 - FROM public.user_account AS u 421 - WHERE u.id = $1; 419 + select u.password_hash 420 + from public.user_account as u 421 + where u.id = $1; 422 422 " 423 423 |> pog.query 424 424 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 470 470 } 471 471 472 472 "-- 󰀖 Find basic information about an user account 473 - SELECT 473 + select 474 474 u.id, 475 475 u.full_name, 476 476 u.registration, 477 477 u.user_role, 478 478 u.email, 479 479 u.phone 480 - FROM public.user_account AS u 481 - WHERE u.id = $1; 480 + from public.user_account as u 481 + where u.id = $1; 482 482 " 483 483 |> pog.query 484 484 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 511 511 } 512 512 513 513 "-- 󰀖 Find user access level 514 - SELECT u.user_role 515 - FROM 516 - public.user_account AS u 517 - WHERE u.id = $1; 514 + select u.user_role 515 + from 516 + public.user_account as u 517 + where u.id = $1; 518 518 " 519 519 |> pog.query 520 520 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 535 535 let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 536 536 537 537 "--  Set an new value to the password of an user 538 - UPDATE public.user_account 539 - SET 538 + update public.user_account 539 + set 540 540 password_hash = $2, 541 - updated_at = CURRENT_TIMESTAMP 542 - WHERE id = $1; 541 + updated_at = current_timestamp 542 + where id = $1; 543 543 " 544 544 |> pog.query 545 545 |> pog.parameter(pog.text(uuid.to_string(arg_1))) ··· 578 578 } 579 579 580 580 "--  Update an authenticated user profile 581 - UPDATE public.user_account AS u SET 581 + update public.user_account as u set 582 582 full_name = $2, 583 583 email = $3, 584 584 phone = $4 585 - WHERE u.id = $1 586 - RETURNING 585 + where u.id = $1 586 + returning 587 587 u.full_name, 588 588 u.email, 589 589 u.phone; ··· 624 624 } 625 625 626 626 "-- 󰚰 Update an user `is_active` field 627 - UPDATE public.user_account AS u 628 - SET 627 + update public.user_account as u 628 + set 629 629 is_active = $2, 630 - updated_at = CURRENT_TIMESTAMP 631 - WHERE u.id = $1 632 - RETURNING u.id, u.is_active; 630 + updated_at = current_timestamp 631 + where u.id = $1 632 + returning u.id, u.is_active; 633 633 " 634 634 |> pog.query 635 635 |> pog.parameter(pog.text(uuid.to_string(arg_1)))