packages feed

apiary-redis (empty) → 1.5.0

raw patch · 4 files changed

+102/−0 lines, 4 filesdep +apiarydep +basedep +hedissetup-changed

Dependencies added: apiary, base, hedis, transformers

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Hirotomo Moriwaki++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ apiary-redis.cabal view
@@ -0,0 +1,32 @@+name:                apiary-redis+version:             1.5.0+synopsis:            redis support for apiary web framework.+description:+  example: <https://github.com/philopon/apiary/blob/master/examples/redis.hs>+license:             MIT+license-file:        LICENSE+author:              Winter Han<drkoster@qq.com>+maintainer:          Winter Han<drkoster@qq.com>+Homepage:            https://github.com/philopon/apiary+Bug-reports:         https://github.com/philopon/apiary/issues+copyright:           (c) 2017 Winter Han+category:            Web+build-type:          Simple+stability:           stable+-- extra-source-files:  +cabal-version:       >=1.10++library+  exposed-modules:     Web.Apiary.Database.Redis+  build-depends:       base               >=4.7   && <5.0+                     , hedis              >= 0.9.0   && <1.0+                     , apiary             >=2.1   && <3.0+                     , transformers       >=0.2   && <0.6++  hs-source-dirs:      src+  ghc-options:         -O2 -Wall+  default-language:    Haskell2010++source-repository head+  type:     git+  location: git://github.com/philopon/apiary.git
+ src/Web/Apiary/Database/Redis.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE GADTs #-}++module Web.Apiary.Database.Redis+    ( -- * initializer+      initRedis+    -- * query+    , runRedis+    , runRedisTx+    ) where++import Control.Monad.IO.Class(MonadIO(..))+import qualified Database.Redis as Redis+import Data.Proxy(Proxy(..))+import Data.Apiary.Extension+    (Has, Initializer, initializer', Extension, MonadExts, getExt)++newtype RedisConn = RedisConn Redis.Connection++instance Extension RedisConn++-- | construct persist extension initializer with no connection pool.+--+-- example:+--+-- @+-- initPersist (withSqliteConn "db.sqlite") migrateAll+-- @+initRedis :: (Monad m)+             => Redis.Connection -> Initializer m exts (RedisConn ': exts)+initRedis conn = initializer' $ return (RedisConn conn)++runRedis :: (MonadExts es m, Has RedisConn es, MonadIO m) => Redis.Redis a -> m a+runRedis r = do+    getExt (Proxy :: Proxy RedisConn) >>= \ (RedisConn c) ->+        liftIO $ Redis.runRedis c r++runRedisTx :: (MonadExts es m, Has RedisConn es, MonadIO m)+           => Redis.RedisTx (Redis.Queued a) -> m (Redis.TxResult a)+runRedisTx r = do+    getExt (Proxy :: Proxy RedisConn) >>= \ (RedisConn c) ->+        liftIO . Redis.runRedis c $ Redis.multiExec r