File: withTC.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 (13 lines) | stat: -rw-r--r-- 428 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
module Main where

import Control.Monad.Trans
import Control.Exception
import Database.TokyoCabinet

withTokyoCabinet :: (TCDB a) => String -> (a -> TCM b) -> TCM b
withTokyoCabinet fname action =
    liftIO $ bracket (runTCM open') (runTCM . close') (runTCM . action)
    where  open' = do tc <- new
                      open tc fname [OREADER, OWRITER, OCREAT]
                      return tc
           close' tc = close tc