wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam
at main 175 lines 5.6 kB view raw
1//// This module contains the code to run the sql queries defined in 2//// `./src/app/domain/notification/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 9import youid/uuid.{type Uuid} 10 11/// A row you get from running the `query_active_notifications` query 12/// defined in `./src/app/domain/notification/sql/query_active_notifications.sql`. 13/// 14/// > 🐿️ This type definition was generated automatically using v4.6.0 of the 15/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 16/// 17pub type QueryActiveNotificationsRow { 18 QueryActiveNotificationsRow(notification_type: NotificationTypeEnum) 19} 20 21///  Find the active notifications from an user 22/// 23/// > 🐿️ This function was generated automatically using v4.6.0 of 24/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 25/// 26pub fn query_active_notifications( 27 db: pog.Connection, 28 arg_1: Uuid, 29) -> Result(pog.Returned(QueryActiveNotificationsRow), pog.QueryError) { 30 let decoder = { 31 use notification_type <- decode.field(0, notification_type_enum_decoder()) 32 decode.success(QueryActiveNotificationsRow(notification_type:)) 33 } 34 35 "--  Find the active notifications from an user 36select np.notification_type 37from public.user_notification_preference as np 38where 39 np.user_id = $1 40 and np.enabled = true; 41" 42 |> pog.query 43 |> pog.parameter(pog.text(uuid.to_string(arg_1))) 44 |> pog.returning(decoder) 45 |> pog.execute(db) 46} 47 48/// A row you get from running the `query_notification_preferences` query 49/// defined in `./src/app/domain/notification/sql/query_notification_preferences.sql`. 50/// 51/// > 🐿️ This type definition was generated automatically using v4.6.0 of the 52/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 53/// 54pub type QueryNotificationPreferencesRow { 55 QueryNotificationPreferencesRow( 56 notification_type: NotificationTypeEnum, 57 enabled: Bool, 58 ) 59} 60 61///  Find the notification preferences for an user 62/// 63/// > 🐿️ This function was generated automatically using v4.6.0 of 64/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 65/// 66pub fn query_notification_preferences( 67 db: pog.Connection, 68 arg_1: Uuid, 69) -> Result(pog.Returned(QueryNotificationPreferencesRow), pog.QueryError) { 70 let decoder = { 71 use notification_type <- decode.field(0, notification_type_enum_decoder()) 72 use enabled <- decode.field(1, decode.bool) 73 decode.success(QueryNotificationPreferencesRow(notification_type:, enabled:)) 74 } 75 76 "--  Find the notification preferences for an user 77select 78 np.notification_type, 79 np.enabled 80from public.user_notification_preference as np 81where np.user_id = $1; 82" 83 |> pog.query 84 |> pog.parameter(pog.text(uuid.to_string(arg_1))) 85 |> pog.returning(decoder) 86 |> pog.execute(db) 87} 88 89/// A row you get from running the `update_notification_preferences` query 90/// defined in `./src/app/domain/notification/sql/update_notification_preferences.sql`. 91/// 92/// > 🐿️ This type definition was generated automatically using v4.6.0 of the 93/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 94/// 95pub type UpdateNotificationPreferencesRow { 96 UpdateNotificationPreferencesRow( 97 notification_type: NotificationTypeEnum, 98 enabled: Bool, 99 ) 100} 101 102///  Update user notification preference 103/// 104/// > 🐿️ This function was generated automatically using v4.6.0 of 105/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 106/// 107pub fn update_notification_preferences( 108 db: pog.Connection, 109 arg_1: Uuid, 110 arg_2: NotificationTypeEnum, 111 arg_3: Bool, 112) -> Result(pog.Returned(UpdateNotificationPreferencesRow), pog.QueryError) { 113 let decoder = { 114 use notification_type <- decode.field(0, notification_type_enum_decoder()) 115 use enabled <- decode.field(1, decode.bool) 116 decode.success(UpdateNotificationPreferencesRow( 117 notification_type:, 118 enabled:, 119 )) 120 } 121 122 "--  Update user notification preference 123update public.user_notification_preference as np 124set 125 enabled = $3, 126 updated_at = current_timestamp 127where 128 np.user_id = $1 129 and np.notification_type = $2 130returning 131 new.notification_type, 132 new.enabled; 133" 134 |> pog.query 135 |> pog.parameter(pog.text(uuid.to_string(arg_1))) 136 |> pog.parameter(notification_type_enum_encoder(arg_2)) 137 |> pog.parameter(pog.bool(arg_3)) 138 |> pog.returning(decoder) 139 |> pog.execute(db) 140} 141 142// --- Enums ------------------------------------------------------------------- 143 144/// Corresponds to the Postgres `notification_type_enum` enum. 145/// 146/// > 🐿️ This type definition was generated automatically using v4.6.0 of the 147/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 148/// 149pub type NotificationTypeEnum { 150 Other 151 Traffic 152 Emergency 153 Fire 154} 155 156fn notification_type_enum_decoder() -> decode.Decoder(NotificationTypeEnum) { 157 use notification_type_enum <- decode.then(decode.string) 158 case notification_type_enum { 159 "other" -> decode.success(Other) 160 "traffic" -> decode.success(Traffic) 161 "emergency" -> decode.success(Emergency) 162 "fire" -> decode.success(Fire) 163 _ -> decode.failure(Other, "NotificationTypeEnum") 164 } 165} 166 167fn notification_type_enum_encoder(notification_type_enum) -> pog.Value { 168 case notification_type_enum { 169 Other -> "other" 170 Traffic -> "traffic" 171 Emergency -> "emergency" 172 Fire -> "fire" 173 } 174 |> pog.text 175}