~singpolyma/tokyocabinet-haskell

1cc7c8699e5d5881bad55a3d0decd3eb30a116fb — tom.lpsd 11 years ago 4048677
Added sample script using adb

Ignore-this: 7e64a8b4a6958c61d4d2cf4bfdabeabb

darcs-hash:20090509045205-69edc-b7b2d2425ce9e66477e89a72021838950205905e.gz
2 files changed, 41 insertions(+), 3 deletions(-)

A examples/tcadb.hs
M tokyocabinet-haskell.cabal
A examples/tcadb.hs => examples/tcadb.hs +31 -0
@@ 0,0 1,31 @@
import Control.Monad
import Database.TokyoCabinet.ADB

main = do adb <- new
          -- open the abstract database object
          -- "+" means that the database will be an on-memory tree database
          open adb "+" >>= err adb "open failed"
          -- store records
          puts adb [("foo", "hop"), ("bar", "step"), ("baz", "jump")]
                   >>= err adb "put failed" . (all id)
          -- retrieve records
          get_print adb "foo"
          -- traverse records
          iterinit adb
          iter adb >>= mapM_ (\k -> putStr (k++":") >> get_print adb k)
          -- close the database
          close adb >>= err adb "close failed"
    where
      puts :: ADB -> [(String, String)] -> IO [Bool]
      puts adb = mapM (uncurry $ put adb)

      get_print :: ADB -> String -> IO ()
      get_print adb key = get adb key >>=
                          maybe (error "something goes wrong") putStrLn

      err :: ADB -> String -> Bool -> IO ()
      err adb msg = flip unless $ error msg

      iter :: ADB -> IO [String]
      iter adb = iternext adb >>=
                 maybe (return []) (\x -> return . (x:) =<< iter adb)

M tokyocabinet-haskell.cabal => tokyocabinet-haskell.cabal +10 -3
@@ 9,7 9,11 @@ Homepage:       http://tom-lpsd.github.com/tokyocabinet-haskell/
Stability:      experimental
Category:       Database
Synopsis:       Haskell binding of Tokyo Cabinet
Extra-source-files: tests/*.hs examples/*.hs
Extra-source-files: examples/tcfdb.hs examples/tcbdb.hs examples/tctdb.hs
                    examples/tchdb.hs examples/tcadb.hs examples/simple.hs
                    examples/myapp1.hs examples/myapp2.hs
                    examples/MyApp1/TokyoCabinet.hs
                    examples/MyApp2/TokyoCabinet.hs
Description:
  Bindings to Tokyo Cabinet library.
  Tokyo Cabinet is a modern implementation of DBM.


@@ 19,11 23,15 @@ Description:
  See, <http://tokyocabinet.sourceforge.net/tokyocabinet.idl>.
  
  This version 0.0.5 depends on tokyocabinet-1.4.19(or later version).
  At first, you should install the latest version of Tokyo Cabinet.
  First of all you should install the latest version of Tokyo Cabinet.

Tested-With:    GHC
Build-Type:     Simple

Source-Repository head
  type: git
  location: git://github.com/tom-lpsd/tokyocabinet-haskell.git

Flag BuildTest
  Description:  make tests and install it if True
  Default:      False


@@ 207,7 215,6 @@ Executable ADBTest
  Build-depends:        HUnit >= 1.2, base >= 4.0, directory >= 1.0
  Extensions:           CPP, ForeignFunctionInterface,
                        EmptyDataDecls, TypeSynonymInstances
  GHC-Options:          -fhpc
  Other-modules:
    TestUtil
    Database.TokyoCabinet.ADB