blob: 89eb57d71b04a009af1012e1175fd98a0d5af474 (
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
38
39
40
|
module Persistence.User
( list
, get
) where
import qualified Data.Maybe as Maybe
import Data.Text (Text)
import Database.SQLite.Simple (FromRow (fromRow), NamedParam ((:=)))
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 email =
Query (\conn -> do
fmap (\(Row u) -> u) . Maybe.listToMaybe <$>
SQLite.queryNamed
conn
"SELECT * FROM user WHERE email = :email LIMIT 1"
[ ":email" := email ]
)
|