leveldb-haskell-0.0.1: Haskell bindings to LevelDB

Safe HaskellNone

Database.LevelDB

Contents

Description

LevelDB Haskell binding.

The API closely follows the C-API of LevelDB. For more information, see: http://leveldb.googlecode.com

Basic example:

 withLevelDB "/tmp/leveldbtest" [CreateIfMissing, CacheSize 1024] $ \db -> do
     put db [] "foo" "bar"
     get db [] "foo" >>= print
     delete db [] "foo"
     get db [] "foo" >>= print

Batch write and iterating:

 withLevelDB "/tmp/leveldbtest" [CreateIfMissing, CacheSize 1024] $ \db -> do
     write db [Sync] [ Put "a" "one"
                     , Put "b" "two"
                     , Put "c" "three" ]
     dumpEntries db []

     where
         dumpEntries db opts =
             withIterator db opts $ \iter -> do
                 iterFirst iter
                 iterEntries iter print

         iterEntries iter f = do
             valid <- iterValid iter
             when valid $ do
                 key <- iterKey iter
                 val <- iterValue iter
                 _   <- f (key, val)
                 _   <- iterNext iter
                 iterEntries iter f

Synopsis

Exported Types

data DB Source

Database handle

data BatchOp Source

Batch operation

Instances

data Compression Source

Compression setting

Constructors

NoCompression 
Snappy 

data ReadOption Source

Options for read operations

data Snapshot Source

Snapshot handle

data WriteOption Source

Options for write operations

Constructors

Sync

fsync the rows written immediately

Instances

Basic Database Manipulation

withLevelDB :: FilePath -> Options -> (DB -> IO a) -> IO aSource

Run an action on a database

withSnapshot :: DB -> (Snapshot -> IO a) -> IO aSource

Run an action with a snapshot of the database.

put :: DB -> WriteOptions -> ByteString -> ByteString -> IO ()Source

Write a key/value pair

delete :: DB -> WriteOptions -> ByteString -> IO ()Source

Delete a key/value pair

write :: DB -> WriteOptions -> WriteBatch -> IO ()Source

Perform a batch mutation

get :: DB -> ReadOptions -> ByteString -> IO (Maybe ByteString)Source

Read a value by key

Administrative Functions

data Property Source

Properties exposed by LevelDB

Instances

getProperty :: DB -> Property -> IO (Maybe ByteString)Source

Get a DB property

destroy :: FilePath -> Options -> IO ()Source

Destroy the given leveldb database.

repair :: FilePath -> Options -> IO ()Source

Repair the given leveldb database.

approximateSize :: DB -> Range -> IO Int64Source

Inspect the approximate sizes of the different levels

Iteration

data Iterator Source

Iterator handle

withIterator :: DB -> ReadOptions -> (Iterator -> IO a) -> IO aSource

Run an action with an Iterator. The iterator will be closed after the action returns or an error is thrown. Thus, the iterator will not be valid after this function terminates.

iterOpen :: DB -> ReadOptions -> IO IteratorSource

Create an Iterator. Consider using withIterator.

iterClose :: Iterator -> IO ()Source

Release an Iterator. Consider using withIterator.

iterValid :: Iterator -> IO BoolSource

An iterator is either positioned at a key/value pair, or not valid. This function returns true iff the iterator is valid.

iterSeek :: Iterator -> ByteString -> IO ()Source

Position at the first key in the source that is at or past target. The iterator is valid after this call iff the source contains an entry that comes at or past target.

iterFirst :: Iterator -> IO ()Source

Position at the first key in the source. The iterator is valid after this call iff the source is not empty.

iterLast :: Iterator -> IO ()Source

Position at the last key in the source. The iterator is valid after this call iff the source is not empty.

iterNext :: Iterator -> IO ()Source

Moves to the next entry in the source. After this call, iterValid is true iff the iterator was not positioned the last entry in the source.

iterPrev :: Iterator -> IO ()Source

Moves to the previous entry in the source. After this call, iterValid is true iff the iterator was not positioned at the first entry in the source.

iterKey :: Iterator -> IO ByteStringSource

Return the key for the current entry. The underlying storage for the returned slice is valid only until the next modification of the iterator.

iterValue :: Iterator -> IO ByteStringSource

Return the value for the current entry. The underlying storage for the returned slice is valid only until the next modification of the iterator.