blob: 3c3a2b1525f2cbf5a11659a1f0ec0e350bb37ba3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
module Persistence.User
( list
, get
) where
import qualified Data.Maybe as Maybe
import Data.Text (Text)
import Database.SQLite.Simple (FromRow (fromRow), Only (Only))
import qualified Database.SQLite.Simple as SQLite
import Prelude hiding (id)
import Common.Model (User (..))
import Model.Query (Query (Query))
newtype Row = Row User
instance FromRow Row where
fromRow = Row <$> (User <$>
SQLite.field <*>
SQLite.field <*>
SQLite.field <*>
SQLite.field)
list :: Query [User]
list =
Query (\conn -> do
map (\(Row u) -> u) <$>
SQLite.query_ conn "SELECT * from user ORDER BY creation DESC"
)
get :: Text -> Query (Maybe User)
get userEmail =
Query (\conn -> do
fmap (\(Row u) -> u) . Maybe.listToMaybe <$>
SQLite.query conn "SELECT * FROM user WHERE email = ? LIMIT 1" (Only userEmail)
)
|