mail based rss feed aggregator
2
fork

Configure Feed

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

add user_by_email query to database

ollie 045e1923 c7e7650a

+44
+25
src/eater/database.gleam
··· 125 125 |> Ok 126 126 } 127 127 128 + /// gets a specific user using the associated email 129 + /// 130 + pub fn user_by_email( 131 + in on: sqlight.Connection, 132 + email email: String, 133 + ) -> Result(Result(user.User, Nil), sqlight.Error) { 134 + let #(sql, with, expecting) = sql.user_by_email(email:) 135 + 136 + let with = list.map(with, parrot_to_sqlight) 137 + 138 + use user <- result.try(sqlight.query(sql, on:, with:, expecting:)) 139 + 140 + case user { 141 + [] -> Error(Nil) 142 + [user, ..] -> { 143 + let assert Ok(id) = uuid.from_bit_array(user.id) 144 + as "invalid UUID from db UUID column?!" 145 + 146 + user.User(id, user.email) 147 + |> Ok 148 + } 149 + } 150 + |> Ok 151 + } 152 + 128 153 // updates ---------------------------------------------------------------------- 129 154 130 155 /// checks if a given `user` has been sent a given `item`
+15
src/eater/sql.gleam
··· 93 93 decode.success(AllUsers(id:, email:)) 94 94 } 95 95 96 + pub type UserByEmail { 97 + UserByEmail(id: BitArray, email: String) 98 + } 99 + 100 + pub fn user_by_email(email email: String) { 101 + let sql = "SELECT id, email FROM users WHERE users.email = ? LIMIT 1" 102 + #(sql, [dev.ParamString(email)], user_by_email_decoder()) 103 + } 104 + 105 + pub fn user_by_email_decoder() -> decode.Decoder(UserByEmail) { 106 + use id <- decode.field(0, decode.bit_array) 107 + use email <- decode.field(1, decode.string) 108 + decode.success(UserByEmail(id:, email:)) 109 + } 110 + 96 111 pub type WasUpdateSentToUser { 97 112 WasUpdateSentToUser(count: Int) 98 113 }
+4
src/eater/sql/users.sql
··· 25 25 -- name: AllUsers :many 26 26 SELECT * FROM users; 27 27 28 + -- name: UserByEmail :one 29 + SELECT * FROM users WHERE users.email = ? LIMIT 1; 30 + 31 + 28 32 -- name: WasUpdateSentToUser :one 29 33 SELECT count(*) 30 34 FROM feed_updates AS updates