File: tcfdb.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 (19 lines) | stat: -rw-r--r-- 679 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
import Control.Monad
import Database.TokyoCabinet.FDB

main = do fdb <- new
          -- open the database
          open fdb "casket.tcf" [OWRITER, OCREAT] >>= err fdb
          -- store records
          puts fdb [(1, "one"), (12, "twelve"), (144, "one forty four")]
                    >>= err fdb . (all id)
          -- retrieve records
          get fdb (1 :: Int) >>= maybe (error "something goes wrong") putStrLn
          -- close the database
          close fdb >>= err fdb
    where
      puts :: FDB -> [(Int, String)] -> IO [Bool]
      puts fdb = mapM (uncurry $ put fdb)

      err :: FDB -> Bool -> IO ()
      err fdb = flip unless $ ecode fdb >>= error . show