Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | kim.altintop@gmail.com |
Safe Haskell | Safe-Infered |
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 iterItems iter >>= print
- data DB
- data BatchOp
- data Compression
- = NoCompression
- | Snappy
- data Option
- type Options = [Option]
- data ReadOption
- type ReadOptions = [ReadOption]
- data Snapshot
- type WriteBatch = [BatchOp]
- data WriteOption = Sync
- type WriteOptions = [WriteOption]
- type Range = (ByteString, ByteString)
- withLevelDB :: FilePath -> Options -> (DB -> IO a) -> IO a
- withSnapshot :: DB -> (Snapshot -> IO a) -> IO a
- put :: DB -> WriteOptions -> ByteString -> ByteString -> IO ()
- delete :: DB -> WriteOptions -> ByteString -> IO ()
- write :: DB -> WriteOptions -> WriteBatch -> IO ()
- get :: DB -> ReadOptions -> ByteString -> IO (Maybe ByteString)
- data Property
- = NumFilesAtLevel Int
- | Stats
- | SSTables
- getProperty :: DB -> Property -> IO (Maybe ByteString)
- destroy :: FilePath -> Options -> IO ()
- repair :: FilePath -> Options -> IO ()
- approximateSize :: DB -> Range -> IO Int64
- data Iterator
- withIterator :: DB -> ReadOptions -> (Iterator -> IO a) -> IO a
- iterOpen :: DB -> ReadOptions -> IO Iterator
- iterClose :: Iterator -> IO ()
- iterValid :: Iterator -> IO Bool
- iterSeek :: Iterator -> ByteString -> IO ()
- iterFirst :: Iterator -> IO ()
- iterLast :: Iterator -> IO ()
- iterNext :: Iterator -> IO ()
- iterPrev :: Iterator -> IO ()
- iterKey :: Iterator -> IO ByteString
- iterValue :: Iterator -> IO ByteString
- mapIter :: (Iterator -> IO a) -> Iterator -> IO [a]
- iterItems :: Iterator -> IO [(ByteString, ByteString)]
- iterKeys :: Iterator -> IO [ByteString]
- iterValues :: Iterator -> IO [ByteString]
Exported Types
Options when opening a database
data ReadOption Source
Options for read operations
type ReadOptions = [ReadOption]Source
type WriteBatch = [BatchOp]Source
type WriteOptions = [WriteOption]Source
type Range = (ByteString, ByteString)Source
Basic Database Manipulation
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
Properties exposed by LevelDB
getProperty :: DB -> Property -> IO (Maybe ByteString)Source
Get a DB property
approximateSize :: DB -> Range -> IO Int64Source
Inspect the approximate sizes of the different levels
Iteration
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.
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.
mapIter :: (Iterator -> IO a) -> Iterator -> IO [a]Source
Map a function over an iterator, returning the value. The iterator should be put in the right position prior to calling this with the iterator.
iterItems :: Iterator -> IO [(ByteString, ByteString)]Source
Return a list of key and value tuples from an iterator. The iterator should be put in the right position prior to calling this with the iterator.
iterKeys :: Iterator -> IO [ByteString]Source
Return a list of key from an iterator. The iterator should be put in the right position prior to calling this with the iterator.
iterValues :: Iterator -> IO [ByteString]Source
Return a list of values from an iterator. The iterator should be put in the right position prior to calling this with the iterator.