packages feed

rocksdb-query 0.1.1 → 0.1.2

raw patch · 3 files changed

+62/−9 lines, 3 files

Files

CHANGELOG.md view
@@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.1.2+### Added+- Documentation for all functions.+ ## 0.1.1 ### Changed - Separate package dependencies.
rocksdb-query.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 9f3e47ecf153da8c0f3c35265b497ca684be47d22cced1ca0a48d129e3e39db0+-- hash: dd06f47b01071602c32222c3f44072c5ec442ff18584fb8ab966326128b16053  name:           rocksdb-query-version:        0.1.1+version:        0.1.2 synopsis:       RocksDB database querying library for Haskell description:    Please see the README on GitHub at <https://github.com/xenog/rocksdb-query#readme> category:       Database
src/Database/RocksDB/Query.hs view
@@ -3,16 +3,15 @@ module Database.RocksDB.Query where  import qualified Data.ByteString          as B-import           Data.Conduit-import qualified Data.Conduit.Combinators as CC+import           Conduit import           Data.Serialize           as S import           Database.RocksDB         as R import           UnliftIO-import           UnliftIO.Resource  class Key key class KeyValue key value +-- | Read a value from the database, or 'Nothing' if not found. retrieve ::        (MonadIO m, KeyValue key value, Serialize key, Serialize value)     => DB@@ -53,6 +52,45 @@   where     base_bytes = encode base +-- | Use the passed key to filter all the elements whose key prefix match it.+-- Use a sum type for keys that allows to set a version of the key that has a+-- shorter length when serialized..+--+-- > #!/usr/bin/env stack+-- > {- stack+-- >   --resolver lts-12.9+-- >   --install-ghc+-- >   runghc+-- >   --package base+-- >   --package cereal+-- >   --package conduit+-- >   --package rocksdb-haskell-1.0.1+-- >   --package rocksdb-query-0.1.2+-- >   --+-- >   -hide-all-packages+-- >   -}+-- > {-# LANGUAGE FlexibleInstances     #-}+-- > {-# LANGUAGE MultiParamTypeClasses #-}+-- > import           Conduit+-- > import           Data.Serialize+-- > import           Database.RocksDB       (createIfMissing, defaultOptions, open)+-- > import           Database.RocksDB.Query (KeyValue, insert, matching)+-- > 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 Nothing (ShortKey "hello") .| headC+-- >   print (record :: (MyKey, String))+--+-- In this example you may serialize the @ShortKey@ and match all the elements+-- in the database that start with it as a prefix. Deserializing will always+-- yield a @FullKey@. matching ::        ( MonadResource m        , KeyValue key value@@ -69,6 +107,8 @@         iterSeek it (encode base)         matchRecursive base it +-- | Like 'matching', but skip to the second key passed as argument, or after if+-- there is no entry for the second key. matchingSkip ::        ( MonadResource m        , KeyValue key value@@ -86,6 +126,7 @@         iterSeek it (encode start)         matchRecursive base it +-- | Insert a record into the database. insert ::        (MonadIO m, KeyValue key value, Serialize key, Serialize value)     => DB@@ -94,9 +135,11 @@     -> m () insert db key value = R.put db defaultWriteOptions (encode key) (encode value) +-- | Delete a record from the database. remove :: (MonadIO m, Key key, Serialize key) => DB -> key -> m () remove db key = delete db defaultWriteOptions (encode key) +-- | Get the 'BatchOp' to insert a record in the database. insertOp ::        (KeyValue key value, Serialize key, Serialize value)     => key@@ -104,12 +147,15 @@     -> BatchOp insertOp key value = R.Put (encode key) (encode value) +-- | Get the 'BatchOp' to delete a record from the database. deleteOp :: (Key key, Serialize key) => key -> BatchOp deleteOp key = Del (encode key) +-- | Write a batch to the database. writeBatch :: MonadIO m => DB -> WriteBatch -> m () writeBatch db = write db defaultWriteOptions +-- | Like 'matching' but return the first element only. firstMatching ::        ( MonadUnliftIO m        , KeyValue key value@@ -121,8 +167,9 @@     -> key     -> m (Maybe (key, value)) firstMatching db snapshot base =-    runResourceT . runConduit $ matching db snapshot base .| CC.head+    runResourceT . runConduit $ matching db snapshot base .| headC +-- | Like 'matchingSkip', but return the first element only. firstMatchingSkip ::        ( MonadUnliftIO m        , KeyValue key value@@ -136,8 +183,9 @@     -> m (Maybe (key, value)) firstMatchingSkip db snapshot base start =     runResourceT . runConduit $-    matchingSkip db snapshot base start .| CC.head+    matchingSkip db snapshot base start .| headC +-- | Like 'matching' but return a list. matchingAsList ::        ( MonadUnliftIO m        , KeyValue key value@@ -150,8 +198,9 @@     -> m [(key, value)] matchingAsList db snapshot base =     runResourceT . runConduit $-    matching db snapshot base .| CC.sinkList+    matching db snapshot base .| sinkList +-- | Like 'matchingSkip', but return a list. matchingSkipAsList ::        ( MonadUnliftIO m        , KeyValue key value@@ -165,4 +214,4 @@     -> m [(key, value)] matchingSkipAsList db snapshot base start =     runResourceT . runConduit $-    matchingSkip db snapshot base start .| CC.sinkList+    matchingSkip db snapshot base start .| sinkList