gdritter repos tansu / 5e161b4
Simple sample program for testing Getty Ritter 8 years ago
2 changed file(s) with 41 addition(s) and 0 deletion(s). Collapse all Expand all
1 module Main where
2
3 import Control.Monad (void)
4 import Database.Tansu
5 import Database.Tansu.Backend.Filesystem
6 import Database.Tansu.Backend.Ephemeral
7
8 main :: IO ()
9 main = do
10 putStrLn "Testing filesystem db"
11 withFilesystemDb "sample.db" sample
12
13 putStrLn "Testing ephemeral db"
14 withEphemeralDb sample
15
16 sample :: Database -> IO ()
17 sample db = do
18 putStrLn "Populating test database"
19 run db $ do
20 "one" =: "un"
21 "two" =: "du"
22 "three" =: "tri"
23 "four" =: "kvar"
24
25 putStr "looking up key 'three': "
26 rs <- run db $ get "three"
27 case rs of
28 Right val -> putStrLn val
29 Left _ -> putStrLn "...not in the database."
30
31 putStr "looking up key 'five': "
32 rs <- run db $ get "five"
33 case rs of
34 Right val -> putStrLn val
35 Left _ -> putStrLn "...not in the database."
2626 base64-bytestring,
2727 containers
2828 default-language: Haskell2010
29
30 executable sample
31 main-is: Main.hs
32 build-depends: base, tansu
33 hs-source-dirs: sample
34 default-language: Haskell2010