packages feed

groundhog 0.8 → 0.8.0.1

raw patch · 4 files changed

+37/−1 lines, 4 filesdep +safe-exceptionsdep +transformers-compatPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: safe-exceptions, transformers-compat

API changes (from Hackage documentation)

- Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Time.Clock.UTC.UTCTime
- Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Time.LocalTime.LocalTime.ZonedTime
- Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Time.LocalTime.TimeOfDay.TimeOfDay
- Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Time.Clock.UTC.UTCTime
- Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Time.LocalTime.LocalTime.ZonedTime
- Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Time.LocalTime.TimeOfDay.TimeOfDay
- Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Time.Clock.UTC.UTCTime
- Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Time.LocalTime.LocalTime.ZonedTime
- Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Time.LocalTime.TimeOfDay.TimeOfDay
+ Database.Groundhog.Core: class TryConnectionManager conn
+ Database.Groundhog.Core: runTryDbConn :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn, Exception e) => TryAction e m conn a -> cm -> m (Either SomeException a)
+ Database.Groundhog.Core: runTryDbConn' :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m (Either SomeException a)
+ Database.Groundhog.Core: tryWithConn :: (TryConnectionManager conn, MonadBaseControl IO m, MonadIO m, MonadCatch m) => (conn -> n a) -> (n a -> m (Either SomeException a)) -> conn -> m (Either SomeException a)
+ Database.Groundhog.Core: type TryAction e m conn = ReaderT conn (ExceptT e m)
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Time.Clock.Internal.UTCTime.UTCTime
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Time.Clock.Internal.UTCTime.UTCTime
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Time.Clock.Internal.UTCTime.UTCTime
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
- Database.Groundhog: class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where type Conn m where {
+ Database.Groundhog: class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where {
- Database.Groundhog.Core: class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where type AutoKeyType db type QueryRaw db :: * -> * where {
+ Database.Groundhog.Core: class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where {
- Database.Groundhog.Core: class PersistField v => Embedded v where data Selector v :: * -> * where {
+ Database.Groundhog.Core: class PersistField v => Embedded v where {
- Database.Groundhog.Core: class HasSelectOptions a db r | a -> db r where type HasLimit a type HasOffset a type HasOrder a type HasDistinct a where {
+ Database.Groundhog.Core: class HasSelectOptions a db r | a -> db r where {
- Database.Groundhog.Core: class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where type Conn m where {
+ Database.Groundhog.Core: class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where {
- Database.Groundhog.Core: class (PurePersistField (AutoKey v), PurePersistField (DefaultKey v)) => PersistEntity v where data Field v :: ((* -> *) -> *) -> * -> * data Key v :: * -> * type AutoKey v type DefaultKey v type IsSumType v where {
+ Database.Groundhog.Core: class (PurePersistField (AutoKey v), PurePersistField (DefaultKey v)) => PersistEntity v where {
- Database.Groundhog.Core: class Projection p a | p -> a where type ProjectionDb p db :: Constraint type ProjectionRestriction p r :: Constraint where {
+ Database.Groundhog.Core: class Projection p a | p -> a where {

Files

Database/Groundhog/Core.hs view
@@ -78,6 +78,7 @@   , PersistBackend(..)   , PersistBackendConn(..)   , Action+  , TryAction   , RowStream   , DbDescriptor(..)   , DbPersist@@ -85,18 +86,23 @@   -- * Connections and transactions   , ExtractConnection(..)   , ConnectionManager(..)+  , TryConnectionManager(..)   , Savepoint(..)   , withSavepoint   , runDb   , runDbConn+  , runTryDbConn+  , runTryDbConn'   , runDb'   , runDbConn'   ) where  import Blaze.ByteString.Builder (Builder, fromByteString, toByteString) import Control.Applicative (Applicative)+import Control.Exception.Safe (MonadCatch, SomeException(..), Exception, tryAny) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Trans.Control (MonadBaseControl (..))+import Control.Monad.Trans.Except (ExceptT, runExceptT) import Control.Monad.Trans.Reader (ReaderT(..), runReaderT) import Control.Monad.Trans.State (StateT(..)) import Control.Monad.Reader (MonadReader(..))@@ -339,6 +345,7 @@   getList       :: (PersistField a, PersistBackend m, Conn m ~ conn) => Int64 -> m [a]  type Action conn = ReaderT conn IO+type TryAction e m conn = ReaderT conn (ExceptT e m) type RowStream a = Acquire (IO (Maybe a))  type Migration m = StateT NamedMigrations m ()@@ -561,6 +568,10 @@   -- | Opens the transaction.   withConn :: (MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> conn -> m a +class TryConnectionManager conn where+  -- | Tries the transaction, using a provided function which evaluates to an Either. Any Left result will cause transaction rollback.+  tryWithConn :: (MonadBaseControl IO m, MonadIO m, MonadCatch m) => (conn -> n a) -> (n a ->  m (Either SomeException a)) -> conn -> m (Either SomeException a)+ class Savepoint conn where   -- | Wraps the passed action into a named savepoint   withConnSavepoint :: (MonadBaseControl IO m, MonadIO m) => String -> m a -> conn -> m a@@ -585,6 +596,14 @@ runDbConn :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a runDbConn f cm = extractConn (liftIO . withConn (runReaderT f)) cm +-- | Runs TryAction within connection.+runTryDbConn :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn, Exception e) => TryAction e m conn a -> cm -> m (Either SomeException a)+runTryDbConn f cm = extractConn (tryWithConn (runReaderT f) tryExceptT) cm++-- | Tries Action within connection.+runTryDbConn' :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m (Either SomeException a)+runTryDbConn' f cm = extractConn (liftIO . tryWithConn (runReaderT f) tryAny) cm+ -- | It helps to run database operations within an application monad. Unlike `runDb` it does not wrap action in transaction runDb' :: PersistBackend m => Action (Conn m) a -> m a runDb' f = getConnection >>= liftIO . runReaderT f@@ -603,3 +622,15 @@ -- | It helps to run 'withConnSavepoint' within a monad. Make sure that transaction is open withSavepoint :: (PersistBackend m, MonadBaseControl IO m, MonadIO m, Savepoint (Conn m)) => String -> m a -> m a withSavepoint name m = getConnection >>= withConnSavepoint name m++tryExceptT :: ( MonadCatch m+              , Exception e )+           => ExceptT e m a+           -> m (Either SomeException a)+tryExceptT e = do+  outside <- tryAny $ runExceptT e+  case outside of+    Left outsideErr -> return . Left $ outsideErr+    Right inside -> case inside of+      Left insideErr -> return . Left . SomeException $ insideErr+      Right y -> return $ Right y
Database/Groundhog/Generic.hs view
changelog view
@@ -1,3 +1,6 @@+0.8.0.1+* New typeclass to allow transaction rollback through ExceptT+ 0.8 * Simplified signatures for PurePersistField and PrimitivePersistField * Basic support for streaming API
groundhog.cabal view
@@ -1,5 +1,5 @@ name:            groundhog-version:         0.8+version:         0.8.0.1 license:         BSD3 license-file:    LICENSE author:          Boris Lykah <lykahb@gmail.com>@@ -31,6 +31,8 @@                    , monad-control            >= 0.3        && < 1.1                    , transformers-base                    , resourcet                >= 1.1.2+                   , safe-exceptions+                   , transformers-compat      >= 0.3     exposed-modules: Database.Groundhog                      Database.Groundhog.Core                      Database.Groundhog.Expression