Simple sample program for testing
Getty Ritter
9 years ago
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." |