apiary-persistent (empty) → 0.4.2.0
raw patch · 4 files changed
+124/−0 lines, 4 filesdep +basedep +monad-loggerdep +mtlsetup-changed
Dependencies added: base, monad-logger, mtl, persistent, resourcet
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- apiary-persistent.cabal +35/−0
- src/Web/Apiary/Database/Persist.hs +67/−0
+ 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-persistent.cabal view
@@ -0,0 +1,35 @@+name: apiary-persistent+version: 0.4.2.0+x-revision: 1+synopsis: persistent support for apiary web framework.+description:+ example: <https://github.com/philopon/apiary/blob/master/examples/persistent.hs>+license: MIT+license-file: LICENSE+author: HirotomoMoriwaki<philopon.dependence@gmail.com>+maintainer: HirotomoMoriwaki<philopon.dependence@gmail.com>+Homepage: https://github.com/philopon/apiary+Bug-reports: https://github.com/philopon/apiary/issues+copyright: (c) 2014 Hirotomo Moriwaki+category: Web+build-type: Simple+stability: experimental+-- extra-source-files: +cabal-version: >=1.10++library+ exposed-modules: Web.Apiary.Database.Persist+ other-modules: + build-depends: base >=4.7 && <4.8+ , persistent >=1.3 && <1.4+ , monad-logger >=0.3 && <0.4+ , resourcet >=1.1 && <1.2+ , mtl >=2.1 && <2.2++ 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/Persist.hs view
@@ -0,0 +1,67 @@+{-# LANGUAGE ImplicitParams #-}+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE KindSignatures #-}++module Web.Apiary.Database.Persist (+ -- * configuration+ ApiaryPersistConfig+ , defaultApiaryPersistConfig++ -- * runner+ , withWithSqlPool, withWithSqlPool'++ -- * execute sql+ , runSql, runSql'++ -- * types+ , HasPersist, LogRunner++ -- * reexport+ , module Database.Persist.Sql+ ) where++import Database.Persist.Sql+import Control.Monad.Logger+import Control.Monad.Trans+import Control.Monad.Trans.Resource++type HasPersist l =+ ?webApiaryDatabasePersistState :: ApiaryPersistState l++type LogRunner l = forall a. l (ResourceT IO) a -> ResourceT IO a++newtype ApiaryPersistConfig l = ApiaryPersistConfig+ { runLogger :: LogRunner l+ }++defaultApiaryPersistConfig :: ApiaryPersistConfig NoLoggingT+defaultApiaryPersistConfig = ApiaryPersistConfig runNoLoggingT++data ApiaryPersistState l = ApiaryPersistState+ { runLogger' :: LogRunner l+ , getPool :: ConnectionPool+ }++runSql :: (MonadBaseControl IO (l (ResourceT IO)), MonadIO m, HasPersist l) => SqlPersistT (l (ResourceT IO)) a -> m a+runSql = runSql' (runLogger' ?webApiaryDatabasePersistState)++runSql' :: (MonadBaseControl IO logger, MonadIO m, HasPersist logger') => (logger a -> ResourceT IO b) -> SqlPersistT logger a -> m b+runSql' run a =+ liftIO .+ runResourceT .+ run $+ runSqlPool a (getPool ?webApiaryDatabasePersistState)++withWithSqlPool :: (forall a. (ConnectionPool -> m a) -> m a)+ -> (HasPersist NoLoggingT => m b) -> m b+withWithSqlPool = withWithSqlPool' defaultApiaryPersistConfig++withWithSqlPool' :: ApiaryPersistConfig logger+ -> (forall a. (ConnectionPool -> m a) -> m a)+ -> (HasPersist logger => m b) -> m b+withWithSqlPool' conf with m = with $ \pool -> do+ let ?webApiaryDatabasePersistState = ApiaryPersistState (runLogger conf) pool+ m+