wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam
at main 60 lines 2.1 kB view raw
1//// This module contains the code to run the sql queries defined in 2//// `./src/app/domain/dashboard/sql`. 3//// > 🐿️ This module was generated automatically using v4.6.0 of 4//// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5//// 6 7import gleam/dynamic/decode 8import pog 9 10/// A row you get from running the `query_dashboard_stats` query 11/// defined in `./src/app/domain/dashboard/sql/query_dashboard_stats.sql`. 12/// 13/// > 🐿️ This type definition was generated automatically using v4.6.0 of the 14/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 15/// 16pub type QueryDashboardStatsRow { 17 QueryDashboardStatsRow( 18 active_brigades_count: Int, 19 total_occurrences_count: Int, 20 active_occurrences_count: Int, 21 recent_occurrences_count: Int, 22 ) 23} 24 25/// 󱘟 Retrieve stats for the Dashboard page 26/// 27/// > 🐿️ This function was generated automatically using v4.6.0 of 28/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 29/// 30pub fn query_dashboard_stats( 31 db: pog.Connection, 32) -> Result(pog.Returned(QueryDashboardStatsRow), pog.QueryError) { 33 let decoder = { 34 use active_brigades_count <- decode.field(0, decode.int) 35 use total_occurrences_count <- decode.field(1, decode.int) 36 use active_occurrences_count <- decode.field(2, decode.int) 37 use recent_occurrences_count <- decode.field(3, decode.int) 38 decode.success(QueryDashboardStatsRow( 39 active_brigades_count:, 40 total_occurrences_count:, 41 active_occurrences_count:, 42 recent_occurrences_count:, 43 )) 44 } 45 46 "-- 󱘟 Retrieve stats for the Dashboard page 47select 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" 57 |> pog.query 58 |> pog.returning(decoder) 59 |> pog.execute(db) 60}