Copyright | No rights reserved |
---|---|
License | UNLICENSE |
Maintainer | xenog@protonmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Query functions to make interaction with RocksDB stores easier and safer.
Synopsis
- class Key key
- class KeyValue key value
- retrieve :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> m (Maybe value)
- matchRecursive :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => key -> Iterator -> ConduitT () (key, value) m ()
- matching :: (MonadResource m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> ConduitT () (key, value) m ()
- matchingSkip :: (MonadResource m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> key -> ConduitT () (key, value) m ()
- insert :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> key -> value -> m ()
- remove :: (MonadIO m, Key key, Serialize key) => DB -> key -> m ()
- insertOp :: (KeyValue key value, Serialize key, Serialize value) => key -> value -> BatchOp
- deleteOp :: (Key key, Serialize key) => key -> BatchOp
- writeBatch :: MonadIO m => DB -> WriteBatch -> m ()
- firstMatching :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> m (Maybe (key, value))
- firstMatchingSkip :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> key -> m (Maybe (key, value))
- matchingAsList :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> m [(key, value)]
- matchingSkipAsList :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> key -> m [(key, value)]
Documentation
retrieve :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> m (Maybe value) Source #
Read a value from the database, or Nothing
if not found.
matchRecursive :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => key -> Iterator -> ConduitT () (key, value) m () Source #
Internal function for recursively matching a key.
matching :: (MonadResource m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> ConduitT () (key, value) m () Source #
Pass a short key to filter all the elements whose key prefix match it. Use a sum type for keys that allows to create a version of the key that serializes to a prefix of a full key.
data MyKey = ShortKey String | FullKey String String deriving Show instance Serialize MyKey where put (ShortKey a) = put a put (FullKey a b) = put a >> put b get = FullKey <$> get <*> get instance KeyValue MyKey String main = do db <- open "test-db" defaultOptions {createIfMissing = True} insert db (FullKey "hello" "world") "despite all my rage" Just record <- runResourceT . runConduit $ matching db def (ShortKey "hello") .| headC print (record :: (MyKey, String)) -- (Fullkey "hello" "world","despite all my rage")
In this example the ShortKey
is serialized to the prefix of the only
element in the database, which is then returned. Since the get
function of
the Serialize
instance for MyKey
only understands how to deserialize a
FullKey
, then that is what is returned.
matchingSkip :: (MonadResource m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> key -> ConduitT () (key, value) m () Source #
Like matching
, but skip to the second key passed as argument, or after if
there is no entry for the second key.
insert :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> key -> value -> m () Source #
Insert a record into the database.
remove :: (MonadIO m, Key key, Serialize key) => DB -> key -> m () Source #
Delete a record from the database.
insertOp :: (KeyValue key value, Serialize key, Serialize value) => key -> value -> BatchOp Source #
Get the BatchOp
to insert a record in the database.
deleteOp :: (Key key, Serialize key) => key -> BatchOp Source #
Get the BatchOp
to delete a record from the database.
writeBatch :: MonadIO m => DB -> WriteBatch -> m () Source #
Write a batch to the database.
firstMatching :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> m (Maybe (key, value)) Source #
Like matching
but return the first element only.
firstMatchingSkip :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> key -> m (Maybe (key, value)) Source #
Like matchingSkip
, but return the first element only.
matchingAsList :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> m [(key, value)] Source #
Like matching
but return a list.
matchingSkipAsList :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ReadOptions -> key -> key -> m [(key, value)] Source #
Like matchingSkip
, but return a list.