rocksdb-query-0.4.2: RocksDB database querying library for Haskell
CopyrightNo rights reserved
LicenseUNLICENSE
Maintainerxenog@protonmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Database.RocksDB.Query

Description

Query functions to make interaction with RocksDB stores easier and safer.

Synopsis

Documentation

class Key key Source #

Class for types that are database keys.

class KeyValue key value Source #

Class for types that are corresponding database key and value.

retrieve :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> key -> m (Maybe value) Source #

Read a value from the database, or Nothing if not found.

retrieveCF :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ColumnFamily -> key -> m (Maybe value) Source #

retrieveCommon :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> Maybe ColumnFamily -> key -> m (Maybe value) Source #

Read a value from the database, or Nothing if not found.

matchRecursiveList :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => key -> Iterator -> m [(key, value)] Source #

matchRecursive :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => key -> Iterator -> ConduitT i (key, value) m () Source #

Internal function for recursively matching a key.

matching :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => Iterator -> key -> ConduitT i (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 :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => Iterator -> key -> key -> ConduitT i (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.

insertCF :: (MonadIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ColumnFamily -> 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.

removeCF :: (MonadIO m, Key key, Serialize key) => DB -> ColumnFamily -> 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.

insertOpCF :: (KeyValue key value, Serialize key, Serialize value) => ColumnFamily -> 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.

deleteOpCF :: (Key key, Serialize key) => ColumnFamily -> key -> BatchOp Source #

Get the BatchOp to delete a record from the database.

writeBatch :: MonadIO m => DB -> [BatchOp] -> m () Source #

Write a batch to the database.

firstMatching :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> key -> m (Maybe (key, value)) Source #

Like matching but return the first element only.

firstMatchingCF :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ColumnFamily -> 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 -> key -> key -> m (Maybe (key, value)) Source #

Like matchingSkip, but return the first element only.

firstMatchingSkipCF :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ColumnFamily -> 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 -> key -> m [(key, value)] Source #

Like matching but return a list.

matchingAsListCF :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ColumnFamily -> key -> m [(key, value)] Source #

Like matching but return a list.

matchingSkipAsList :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> key -> key -> m [(key, value)] Source #

Like matchingSkip, but return a list.

matchingSkipAsListCF :: (MonadUnliftIO m, KeyValue key value, Serialize key, Serialize value) => DB -> ColumnFamily -> key -> key -> m [(key, value)] Source #

Like matchingSkip, but return a list.