packages feed

apiary-persistent 0.8.0.0 → 0.9.0.0

raw patch · 2 files changed

+38/−8 lines, 2 filesdep +apiarydep ~mtlPVP ok

version bump matches the API change (PVP)

Dependencies added: apiary

Dependency ranges changed: mtl

API changes (from Hackage documentation)

+ Web.Apiary.Database.Persist: class BoolLike a where type family UnBool a
+ Web.Apiary.Database.Persist: instance BoolLike (Maybe a)
+ Web.Apiary.Database.Persist: instance BoolLike [a]
+ Web.Apiary.Database.Persist: sql :: (BoolLike a, Functor n, Monad n, MonadBaseControl IO (ActionT n), HasPersist) => SqlPersistT (ResourceT (ActionT n)) a -> ApiaryT (Snoc as (UnBool a)) n m b -> ApiaryT as n m b
+ Web.Apiary.Database.Persist: unBool :: BoolLike a => a -> Maybe (UnBool a)
- Web.Apiary.Database.Persist: type HasPersist = Given ApiaryPersistState
+ Web.Apiary.Database.Persist: type HasPersist = Given Persist

Files

apiary-persistent.cabal view
@@ -1,5 +1,5 @@ name:                apiary-persistent-version:             0.8.0.0+version:             0.9.0.0 synopsis:            persistent support for apiary web framework. description:   example: <https://github.com/philopon/apiary/blob/master/examples/persistent.hs>@@ -21,9 +21,10 @@   other-modules:          build-depends:       base               >=4.6   && <4.8                      , persistent         >=1.3   && <1.4+                     , apiary             >=0.9   && <0.10                      , monad-logger       >=0.3   && <0.4                      , resourcet          >=1.1   && <1.2-                     , mtl                >=2.1   && <2.2+                     , mtl                >=2.1   && <2.3                      , reflection         >=1.4   && <1.5                      , transformers-base  >=0.4   && <0.5 
src/Web/Apiary/Database/Persist.hs view
@@ -3,6 +3,7 @@ {-# LANGUAGE Rank2Types #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE KindSignatures #-}+{-# LANGUAGE TypeFamilies #-}  module Web.Apiary.Database.Persist (     -- * runner@@ -14,26 +15,54 @@     -- * types     , HasPersist +    -- * filter+    , sql+    , BoolLike(..)+     -- * reexport     , module Database.Persist.Sql     ) where  import Database.Persist.Sql+import Web.Apiary+import Control.Applicative import Control.Monad.Trans.Resource import Data.Reflection+import Data.Apiary.SList+import Control.Monad.Apiary.Filter.Internal -type HasPersist = Given ApiaryPersistState+type HasPersist = Given Persist -newtype ApiaryPersistState = ApiaryPersistState+newtype Persist = Persist     { getPool    :: ConnectionPool     }  runSql :: (MonadBaseControl IO m, HasPersist) => SqlPersistT (ResourceT m) a -> m a-runSql a =-    runResourceT $-    runSqlPool a (getPool given)+runSql a = runResourceT $ runSqlPool a (getPool given)  withWithSqlPool :: (forall a. (ConnectionPool -> m a) -> m a)                 -> (HasPersist => m b) -> m b withWithSqlPool with m = with $ \pool -> -    give (ApiaryPersistState pool) m+    give (Persist pool) m++class BoolLike a where+  type UnBool a+  unBool :: a -> Maybe (UnBool a)++instance BoolLike (Maybe a) where+    type UnBool (Maybe a) = a+    unBool = id++instance BoolLike [a] where+    type UnBool [a] = [a]+    unBool [] = Nothing+    unBool a  = Just a++-- | filter by sql query. since 0.9.0.0.+sql :: (BoolLike a, Functor n, Monad n, MonadBaseControl IO (ActionT n), HasPersist)+    => SqlPersistT (ResourceT (ActionT n)) a+    -> ApiaryT (Snoc as (UnBool a)) n m b+    -> ApiaryT as n m b+sql p = focus $ \l -> do+    r <- runSql p+    maybe empty (\i -> return $ sSnoc l i) $ unBool r