persistent-redis 0.3.2 → 2.5.0
raw patch · 4 files changed
+32/−22 lines, 4 filesdep +http-api-datadep ~hedisdep ~monad-controldep ~persistent
Dependencies added: http-api-data
Dependency ranges changed: hedis, monad-control, persistent, utf8-string
Files
- Database/Persist/Redis/Config.hs +2/−2
- Database/Persist/Redis/Internal.hs +2/−2
- Database/Persist/Redis/Store.hs +22/−13
- persistent-redis.cabal +6/−5
Database/Persist/Redis/Config.hs view
@@ -48,11 +48,11 @@ instance FromJSON R.PortID where parseJSON (Number x) = (return . R.PortNumber . fromInteger . truncate) x- parseJSON _ = fail "couldn't parse port number"+ parseJSON _ = fail "persistent Redis: couldn't parse port number" instance FromJSON RedisAuth where parseJSON (String t) = (return . RedisAuth) t- parseJSON _ = fail "couldn't parse auth"+ parseJSON _ = fail "persistent ResisAuth: couldn't parse auth" -- | Monad reader transformer keeping Redis connection through out the work type RedisT = ReaderT R.Connection
Database/Persist/Redis/Internal.hs view
@@ -1,13 +1,13 @@ {-# LANGUAGE OverloadedStrings #-} module Database.Persist.Redis.Internal- ( toKey+ ( toKey , unKey , mkEntity , toKeyId , toKeyText , toInsertFields , toB- ) where+ ) where import Data.Text (Text, unpack) import qualified Data.Text as T
Database/Persist/Redis/Store.hs view
@@ -17,7 +17,8 @@ import Database.Persist.Redis.Config (RedisT, thisConnection) import Database.Persist.Redis.Internal import Database.Persist.Redis.Update-import Web.PathPieces (PathPiece (..))+import Web.PathPieces (PathPiece(..))+import Web.HttpApiData (ToHttpApiData (..), FromHttpApiData (..), parseUrlPieceMaybe) import Data.Aeson(FromJSON(..), ToJSON(..)) @@ -44,10 +45,20 @@ (Right x) -> return x (Left x) -> fail x -instance PersistStore R.Connection where+instance PersistCore R.Connection where newtype BackendKey R.Connection = RedisKey Text deriving (Show, Read, Eq, Ord, PersistField, FromJSON, ToJSON) +instance PersistStoreRead R.Connection where+ get k = do+ r <- execRedisT $ R.hgetall (unKey k)+ if null r+ then return Nothing+ else do+ Entity _ val <- mkEntity k r+ return $ Just val++instance PersistStoreWrite R.Connection where insert val = do keyId <- execRedisT $ createKey val let textKey = toKeyText val keyId@@ -78,14 +89,6 @@ 1 -> return () _ -> fail "there are a lot of such keys!" - get k = do- r <- execRedisT $ R.hgetall (unKey k)- if null r- then return Nothing- else do- Entity _ val <- mkEntity k r- return $ Just val- update _ [] = return () update k upds = do r <- execRedisT $ R.hgetall (unKey k)@@ -97,10 +100,16 @@ insertKey k val return() -instance PathPiece (BackendKey RedisBackend) where- toPathPiece (RedisKey txt) = txt- fromPathPiece txt = Just $ RedisKey txt +instance ToHttpApiData (BackendKey RedisBackend) where+ toUrlPiece (RedisKey txt) = txt++instance FromHttpApiData (BackendKey RedisBackend) where+ parseUrlPiece = return . RedisKey -- some checking that entity exists and it is in format of entityname_id is omitted++instance PathPiece (BackendKey RedisBackend) where+ toPathPiece = toUrlPiece+ fromPathPiece = parseUrlPieceMaybe instance Sql.PersistFieldSql (BackendKey RedisBackend) where sqlType _ = Sql.SqlOther (pack "doesn't make much sense for Redis backend")
persistent-redis.cabal view
@@ -1,5 +1,5 @@ name: persistent-redis-version: 0.3.2+version: 2.5.0 license: BSD3 license-file: LICENSE author: Pavel Ryzhov <paul@paulrz.cz>@@ -18,20 +18,21 @@ library build-depends: base >= 4.6 && < 5- , hedis >= 0.6.0 && < 0.7.0+ , hedis >= 0.6.0 , bytestring >= 0.10.0.0 && < 0.11.0.0- , persistent >= 2.1 && < 2.2+ , persistent >= 2.5 && < 3 , text >= 1.2.0.0 , aeson >= 0.8 , time >= 1.4 && < 1.6 , attoparsec >= 0.12.0.0 , mtl >= 2.2.0 && < 2.3 , transformers >= 0.4.0.0 && < 0.5.0.0- , monad-control >= 0.3.2.0 && < 0.4- , utf8-string >= 0.3.7 && < 0.4.0+ , monad-control >= 0.3.2.0+ , utf8-string >= 0.3.7 , binary >= 0.7 && < 0.8 , scientific >= 0.3.1 && < 0.4 , path-pieces >= 0.1+ , http-api-data exposed-modules: Database.Persist.Redis