-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.hs
44 lines (31 loc) · 1.17 KB
/
test2.hs
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
41
42
43
44
{-# LANGUAGE RecordWildCards, OverloadedStrings, TemplateHaskell#-}
import HQueries.Queries
import HQueries.Sqlite
import Data.Text (Text)
import qualified Data.Text as T
import Data.Map (Map)
import qualified Data.Map as Map
import Control.Lens
data Session = SessionC{_sUser :: Text, _sSecret :: Text} deriving Show
newtype SessionId = SessionId Text deriving (Show, Eq, Ord)
$(deriveQType ''Session)
$(deriveQKey ''SessionId)
$(makeQLenses ''Session)
sessions = EntityMap WriteAccessFull AutoKeysTypeOnly (EntityRef "sessions" :: EntityRef (Map SessionId Session))
main :: IO ()
main = do
backend <- createSqliteBackend "test.db"
migrateSchema backend [EntityObj sessions]
let dostuff x = do
putStrLn $ T.unpack $ getBackendCode backend x
res <- hQuery backend x
putStrLn $ show res
putStrLn "#####"
let a = getEntity sessions
dostuff (return $ toQuery $ SessionC "1" "2")
dostuff $ insertEntityMapAK (toQuery $ SessionC "ola" "ola") sessions
dostuff a
dostuff $ return $ (view sUserQ) (toQuery $ SessionC "ola" "hello")
dostuff $ do
s <- getEntity sessions
return $ qmap (view sUserQ) (qvalues s)