File: simple.hs

package info (click to toggle)
tokyocabinet-haskell 0.0.5-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 308 kB
  • sloc: haskell: 2,276; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 654 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Database.TokyoCabinet
import Data.ByteString.Char8 (ByteString, pack)

putsample :: String -> [(ByteString, ByteString)] -> TCM Bool
putsample file kv =
    do tc <- new :: TCM HDB
       open tc file [OWRITER, OCREAT]
       mapM (uncurry $ put tc) kv
       close tc
              
getsample :: String -> ByteString -> TCM (Maybe ByteString)
getsample file key =
    do tc <- new :: TCM HDB
       open tc file [OREADER]
       val <- get tc key
       close tc
       return val

main = runTCM (do putsample "foo.tch" [(pack "foo", pack "bar")]
                  getsample "foo.tch" (pack "foo")) >>=
       maybe (return ()) (putStrLn . show)