mail based rss feed aggregator
2
fork

Configure Feed

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

add `AllUpdatesSentToUser` query

ollie 13f5ec6b 965dc7d6

+42
+17
src/eater/database.gleam
··· 228 228 229 229 // updates ---------------------------------------------------------------------- 230 230 231 + /// get a list of updates that were sent to a given user 232 + /// 233 + pub fn updates_sent_to_user( 234 + database on: sqlight.Connection, 235 + user user: user.User, 236 + ) -> Result(List(String), sqlight.Error) { 237 + let #(sql, with, expecting) = 238 + sql.all_updates_sent_to_user(user.id |> uuid.to_bit_array()) 239 + 240 + let with = list.map(with, parrot_to_sqlight) 241 + 242 + use update <- result.try(sqlight.query(sql, on:, with:, expecting:)) 243 + 244 + list.map(update, fn(update) { update.link_to_post }) 245 + |> Ok 246 + } 247 + 231 248 /// checks if a given `user` has been sent a given `item` 232 249 /// 233 250 pub fn was_update_sent_to_user(
+19
src/eater/sql.gleam
··· 149 149 decode.success(UserByEmail(id:, email:, password_hash:, is_admin:)) 150 150 } 151 151 152 + pub type AllUpdatesSentToUser { 153 + AllUpdatesSentToUser(link_to_post: String) 154 + } 155 + 156 + pub fn all_updates_sent_to_user(user_id user_id: BitArray) { 157 + let sql = 158 + "SELECT link_to_post 159 + FROM feed_updates AS updates 160 + WHERE updates.user_id = ?" 161 + #(sql, [dev.ParamBitArray(user_id)], all_updates_sent_to_user_decoder()) 162 + } 163 + 164 + pub fn all_updates_sent_to_user_decoder() -> decode.Decoder( 165 + AllUpdatesSentToUser, 166 + ) { 167 + use link_to_post <- decode.field(0, decode.string) 168 + decode.success(AllUpdatesSentToUser(link_to_post:)) 169 + } 170 + 152 171 pub type WasUpdateSentToUser { 153 172 WasUpdateSentToUser(count: Int) 154 173 }
+6
src/eater/sql/users.sql
··· 31 31 SELECT * FROM users WHERE users.email = ? LIMIT 1; 32 32 33 33 34 + -- name: AllUpdatesSentToUser :many 35 + SELECT link_to_post 36 + FROM feed_updates AS updates 37 + WHERE updates.user_id = ?; 38 + 34 39 -- name: WasUpdateSentToUser :one 35 40 SELECT count(*) 36 41 FROM feed_updates AS updates ··· 43 48 link_to_post 44 49 ) 45 50 values (?, ?); 51 +