Copyright | (c) Boris Sukholitko 2013 |
---|---|
License | BSD3 |
Safe Haskell | None |
Language | Haskell2010 |
Database.PureCDB
Description
A library for reading and writing CDB (Constant Database) files.
CDB files are immutable key-value stores, designed for extremely fast and memory-efficient construction and lookup. They can be as large as 4GB, and at no point in their construction or use must all data be loaded into memory. CDB files can contain multiple values for a given key.
For more information on the CDB file format, please see: http://cr.yp.to/cdb.html
Here's how you make new CDB file:
import qualified Data.ByteString.Char8 as B import Database.PureCDB makeIt :: IO () makeIt = makeCDB (do addBS (B.pack "foo") (B.pack "bar") addBS (B.pack "foo") (B.pack "baz")) "foo.cdb"
You can later use it as in:
getIt :: IO [ByteString] getIt = do f <- openCDB "foo.cdb" bs <- getBS f (B.pack "foo") closeCDB "foo.cdb" return bs
getIt
returns [ "bar", "baz" ] in unspecified order.
Note that pure-cdb
works on strict ByteString'
s only for now.
Writing interface
Write context monad transformer.
makeCDB :: MonadIO m => WriteCDB m a -> FilePath -> m a Source
Runs WriteCDB monad transformer to make the database.
addBS :: MonadIO m => ByteString -> ByteString -> WriteCDB m () Source
Adds key and value to the CDB database.
Reading interface
getBS :: ReadCDB -> ByteString -> IO [ByteString] Source
Fetches key from the database.