Copyright | (c) 2012-2013 The leveldb-haskell Authors (c) 2014 The rocksdb-haskell Authors (c) 2020 Jean-Pierre Rupp |
---|---|
License | BSD3 |
Maintainer | jprupp@protonmail.ch |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
RocksDB Haskell binding.
The API closely follows the C-API of RocksDB.
Synopsis
- data DB = DB {
- rocksDB :: !RocksDB
- columnFamilies :: ![ColumnFamily]
- readOpts :: !ReadOpts
- writeOpts :: !WriteOpts
- data BatchOp
- type Range = (ByteString, ByteString)
- type ColumnFamily = Ptr LColumnFamily
- data Config = Config {
- createIfMissing :: !Bool
- errorIfExists :: !Bool
- paranoidChecks :: !Bool
- maxFiles :: !(Maybe Int)
- prefixLength :: !(Maybe Int)
- bloomFilter :: !Bool
- withDB :: MonadUnliftIO m => FilePath -> Config -> (DB -> m a) -> m a
- withDBCF :: MonadUnliftIO m => FilePath -> Config -> [(String, Config)] -> (DB -> m a) -> m a
- put :: MonadIO m => DB -> ByteString -> ByteString -> m ()
- putCF :: MonadIO m => DB -> ColumnFamily -> ByteString -> ByteString -> m ()
- delete :: MonadIO m => DB -> ByteString -> m ()
- deleteCF :: MonadIO m => DB -> ColumnFamily -> ByteString -> m ()
- write :: MonadIO m => DB -> [BatchOp] -> m ()
- get :: MonadIO m => DB -> ByteString -> m (Maybe ByteString)
- getCF :: MonadIO m => DB -> ColumnFamily -> ByteString -> m (Maybe ByteString)
- withSnapshot :: MonadUnliftIO m => DB -> (DB -> m a) -> m a
- data Property
- getProperty :: MonadIO m => DB -> Property -> m (Maybe ByteString)
- destroy :: MonadIO m => FilePath -> Options -> m ()
- repair :: MonadIO m => FilePath -> Options -> m ()
- approximateSize :: MonadIO m => DB -> Range -> m Int64
- type Iterator = Ptr LIterator
- withIter :: MonadUnliftIO m => DB -> (Iterator -> m a) -> m a
- withIterCF :: MonadUnliftIO m => DB -> ColumnFamily -> (Iterator -> m a) -> m a
- iterEntry :: MonadIO m => Iterator -> m (Maybe (ByteString, ByteString))
- iterFirst :: MonadIO m => Iterator -> m ()
- iterGetError :: MonadIO m => Iterator -> m (Maybe ByteString)
- iterKey :: MonadIO m => Iterator -> m (Maybe ByteString)
- iterLast :: MonadIO m => Iterator -> m ()
- iterNext :: MonadIO m => Iterator -> m ()
- iterPrev :: MonadIO m => Iterator -> m ()
- iterSeek :: MonadIO m => Iterator -> ByteString -> m ()
- iterValid :: MonadIO m => Iterator -> m Bool
- iterValue :: MonadIO m => Iterator -> m (Maybe ByteString)
Exported Types
DB | |
|
type Range = (ByteString, ByteString) Source #
type ColumnFamily = Ptr LColumnFamily Source #
Options
Config | |
|
Basic Database Manipulations
withDB :: MonadUnliftIO m => FilePath -> Config -> (DB -> m a) -> m a Source #
Open a database.
The returned handle should be released with close
.
withDBCF :: MonadUnliftIO m => FilePath -> Config -> [(String, Config)] -> (DB -> m a) -> m a Source #
put :: MonadIO m => DB -> ByteString -> ByteString -> m () Source #
Write a key/value pair.
putCF :: MonadIO m => DB -> ColumnFamily -> ByteString -> ByteString -> m () Source #
deleteCF :: MonadIO m => DB -> ColumnFamily -> ByteString -> m () Source #
get :: MonadIO m => DB -> ByteString -> m (Maybe ByteString) Source #
Read a value by key.
getCF :: MonadIO m => DB -> ColumnFamily -> ByteString -> m (Maybe ByteString) Source #
withSnapshot :: MonadUnliftIO m => DB -> (DB -> m a) -> m a Source #
Run an action with a snapshot of the database.
The DB
object is not valid after the action ends.
Administrative Functions
Properties exposed by RocksDB
getProperty :: MonadIO m => DB -> Property -> m (Maybe ByteString) Source #
Get a DB property.
approximateSize :: MonadIO m => DB -> Range -> m Int64 Source #
Inspect the approximate sizes of the different levels.
Iteration
withIterCF :: MonadUnliftIO m => DB -> ColumnFamily -> (Iterator -> m a) -> m a Source #
iterEntry :: MonadIO m => Iterator -> m (Maybe (ByteString, ByteString)) Source #
Return the current entry as a pair, if the iterator is currently positioned
at an entry, ie. iterValid
.
iterFirst :: MonadIO m => Iterator -> m () Source #
Position at the first key in the source. The iterator is valid after this call iff the source is not empty.
iterGetError :: MonadIO m => Iterator -> m (Maybe ByteString) Source #
Check for errors
Note that this captures somewhat severe errors such as a corrupted database.
iterKey :: MonadIO m => Iterator -> m (Maybe ByteString) Source #
Return the key for the current entry if the iterator is currently
positioned at an entry, ie. iterValid
.
iterLast :: MonadIO m => Iterator -> m () Source #
Position at the last key in the source. The iterator is valid after this call iff the source is not empty.
iterNext :: MonadIO m => Iterator -> m () Source #
Moves to the next entry in the source. After this call, iterValid
is
true iff the iterator was not positioned at the last entry in the source.
If the iterator is not valid, this function does nothing. Note that this is a
shortcoming of the C API: an iterPrev
might still be possible, but we can't
determine if we're at the last or first entry.
iterPrev :: MonadIO m => Iterator -> m () 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.
If the iterator is not valid, this function does nothing. Note that this is a
shortcoming of the C API: an iterNext
might still be possible, but we can't
determine if we're at the last or first entry.
iterSeek :: MonadIO m => Iterator -> ByteString -> m () 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.