pure-cdb-0.1.1: Another pure-haskell CDB (Constant Database) implementation

Safe HaskellNone

Database.PureCDB

Contents

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.

Synopsis

Writing interface

data WriteCDB m a Source

Write context monad transformer.

Instances

MonadTrans WriteCDB 
Monad m => Monad (WriteCDB m) 
Functor m => Functor (WriteCDB m) 
(Monad m, Functor m) => Applicative (WriteCDB m) 
MonadIO m => MonadIO (WriteCDB m) 

makeCDB :: MonadIO m => WriteCDB m a -> FilePath -> m aSource

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

data ReadCDB Source

Read handle for the database.

openCDB :: FilePath -> IO ReadCDBSource

Opens CDB database.

closeCDB :: ReadCDB -> IO ()Source

Closes the database.

getBS :: ReadCDB -> ByteString -> IO [ByteString]Source

Fetches key from the database.