packages feed

groundhog 0.10.0 → 0.11.0

raw patch · 9 files changed

+33/−71 lines, 9 filesdep −blaze-builderPVP ok

version bump matches the API change (PVP)

Dependencies removed: blaze-builder

API changes (from Hackage documentation)

- Database.Groundhog: deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()
- Database.Groundhog.Core: instance (GHC.Base.Monad m, GHC.Base.Applicative m, GHC.Base.Functor m, Control.Monad.IO.Class.MonadIO m, Database.Groundhog.Core.PersistBackendConn conn) => Database.Groundhog.Core.PersistBackend (Control.Monad.Trans.Reader.ReaderT conn m)
- Database.Groundhog.Core: runDbPersist :: Monad m => DbPersist conn m a -> conn -> m a
- Database.Groundhog.Core: type DbPersist = ReaderT
- Database.Groundhog.Generic: deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()
- Database.Groundhog.Generic.Sql: instance Data.String.IsString Database.Groundhog.Core.Utf8
- Database.Groundhog.Generic.Sql: instance GHC.Base.Monoid Database.Groundhog.Core.Utf8
- Database.Groundhog.Generic.Sql: instance GHC.Base.Semigroup Database.Groundhog.Core.Utf8
+ Database.Groundhog.Core: instance (GHC.Base.Monad m, GHC.Base.Applicative m, GHC.Base.Functor m, Control.Monad.IO.Class.MonadIO m, Control.Monad.Fail.MonadFail m, Database.Groundhog.Core.PersistBackendConn conn) => Database.Groundhog.Core.PersistBackend (Control.Monad.Trans.Reader.ReaderT conn m)
+ Database.Groundhog.Core: instance Data.String.IsString Database.Groundhog.Core.Utf8
+ Database.Groundhog.Core: instance GHC.Base.Monoid Database.Groundhog.Core.Utf8
+ Database.Groundhog.Core: instance GHC.Base.Semigroup Database.Groundhog.Core.Utf8
+ Database.Groundhog.Core: instance GHC.Classes.Ord Database.Groundhog.Core.Utf8
- Database.Groundhog: class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where {
+ Database.Groundhog: class (Monad m, Applicative m, Functor m, MonadIO m, MonadFail m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend 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 (Monad m, Applicative m, Functor m, MonadIO m, MonadFail m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where {

Files

Database/Groundhog.hs view
@@ -21,7 +21,6 @@   , limitTo   , offsetBy   , orderBy-  , deleteByKey   -- * Expressions   , (=.)   , (&&.), (||.)
Database/Groundhog/Core.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE GADTs, TypeFamilies, ExistentialQuantification, MultiParamTypeClasses, FunctionalDependencies, FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, EmptyDataDecls, ConstraintKinds, CPP, LiberalTypeSynonyms #-}-{-# LANGUAGE UndecidableInstances #-} -- Required for Projection'-#if __GLASGOW_HASKELL__ >= 800-{-# LANGUAGE UndecidableSuperClasses #-}-#endif+{-# LANGUAGE UndecidableInstances, UndecidableSuperClasses #-} -- Required for Projection'+ -- | This module defines the functions and datatypes used throughout the framework. -- Most of them are for the internal use module Database.Groundhog.Core@@ -25,7 +23,7 @@   , UniqueMarker   , HFalse   , HTrue-  , ZT (..) -- ZonedTime wrapper+  , ZT(..) -- ZonedTime wrapper   , Utf8(..)   , fromUtf8   , delim@@ -81,8 +79,6 @@   , TryAction   , RowStream   , DbDescriptor(..)-  , DbPersist-  , runDbPersist   -- * Connections and transactions   , ExtractConnection(..)   , ConnectionManager(..)@@ -97,9 +93,8 @@   , runDbConn'   ) where -import Blaze.ByteString.Builder (Builder, fromByteString, toByteString)-import Control.Applicative (Applicative) import Control.Exception.Safe (MonadCatch, SomeException(..), Exception, tryAny)+import Control.Monad.Fail (MonadFail) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Trans.Control (MonadBaseControl (..)) import Control.Monad.Trans.Except (ExceptT, runExceptT)@@ -108,11 +103,16 @@ import Control.Monad.Reader (MonadReader(..)) import Data.Acquire (Acquire) import Data.ByteString.Char8 (ByteString)+import Data.ByteString.Lazy (toStrict) import Data.Int (Int64) import Data.Map (Map) import Data.Text (Text)+import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)+import Data.Text.Lazy.Encoding (encodeUtf8) import Data.Time (Day, TimeOfDay, UTCTime) import Data.Time.LocalTime (ZonedTime, zonedTimeToUTC, zonedTimeToLocalTime, zonedTimeZone)+import Data.String (IsString)+import Data.Semigroup (Semigroup) import GHC.Exts (Constraint)  -- | Only instances of this class can be persisted in a database@@ -265,12 +265,6 @@ distinct :: (HasSelectOptions a db r, HasDistinct a ~ HFalse) => a -> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) HTrue distinct opts = (getSelectOptions opts) {distinctOptions = True} -{-# DEPRECATED DbPersist, runDbPersist "Use `PersistBackend` constraint instead. If you need to specify a backend, add (PersistBackend m, Conn m ~ Postgresql) " #-}-type DbPersist = ReaderT--runDbPersist :: Monad m => DbPersist conn m a -> conn -> m a-runDbPersist = runReaderT- class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where   -- | Type of the database default auto-incremented key. For example, Sqlite has Int64   type AutoKeyType db@@ -473,18 +467,15 @@  type EmbeddedDef = EmbeddedDef' String DbType --- | Datatype for incremental building SQL queries newtype Utf8 = Utf8 Builder-instance Eq Utf8 where-  a == b = fromUtf8 a == fromUtf8 b-instance Show Utf8 where-  show = show . fromUtf8-instance Read Utf8 where-  readsPrec prec str = map (\(a, b) -> (Utf8 $ fromByteString a, b)) $ readsPrec prec str+  deriving (Eq, Ord, Show, Semigroup, Monoid, IsString)  fromUtf8 :: Utf8 -> ByteString-fromUtf8 (Utf8 a) = toByteString a+fromUtf8 (Utf8 s) = toStrict $ encodeUtf8 $ toLazyText s +instance Read Utf8 where+  readsPrec prec str = map (\(a, b) -> (Utf8 $ fromText a, b)) $ readsPrec prec str+ -- | A raw value which can be stored in any backend and can be marshalled to -- and from a 'PersistField'. data PersistValue = PersistString String@@ -580,11 +571,11 @@ -- If your monad has several connections, e.g., for main and audit databases, create run*Db function -- runAuditDb :: Action conn a -> m a -class (Monad m, Applicative m, Functor m, MonadIO m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where+class (Monad m, Applicative m, Functor m, MonadIO m, MonadFail m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where   type Conn m   getConnection :: m (Conn m) -instance (Monad m, Applicative m, Functor m, MonadIO m, PersistBackendConn conn) => PersistBackend (ReaderT conn m) where+instance (Monad m, Applicative m, Functor m, MonadIO m, MonadFail m, PersistBackendConn conn) => PersistBackend (ReaderT conn m) where   type Conn (ReaderT conn m) = conn   getConnection = ask 
Database/Groundhog/Generic.hs view
@@ -51,7 +51,6 @@   , streamToList   , mapStream   , joinStreams-  , deleteByKey   ) where  import Database.Groundhog.Core@@ -338,6 +337,3 @@ isSimple [_] = True isSimple _   = False -{-# DEPRECATED deleteByKey "Use deleteBy instead" #-}-deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()-deleteByKey = deleteBy
Database/Groundhog/Generic/Migration.hs view
@@ -25,7 +25,6 @@ import Database.Groundhog.Generic import Database.Groundhog.Generic.Sql (flatten, mainTableName, tableName) -import Control.Applicative (Applicative) import Control.Arrow ((***), (&&&)) import Control.Monad (liftM, when) import Control.Monad.Trans.Class (lift)
Database/Groundhog/Generic/PersistBackendHelpers.hs view
@@ -32,7 +32,6 @@ import Control.Monad (liftM) import Data.Either (rights) import Data.Maybe (catMaybes, fromJust, mapMaybe)-import Data.Monoid hiding ((<>))  get :: forall conn v . (PersistBackendConn conn, PersistEntity v, PrimitivePersistField (Key v BackendSpecific))     => RenderConfig -> (Utf8 -> [PersistValue] -> Action conn (RowStream [PersistValue])) -> Key v BackendSpecific -> Action conn (Maybe v)
Database/Groundhog/Generic/Sql.hs view
@@ -23,8 +23,8 @@     , flatten     , RenderS(..)     , Utf8(..)-    , RenderConfig(..)     , fromUtf8+    , RenderConfig(..)     , StringLike(..)     , fromString     , (<>)@@ -42,19 +42,15 @@ import Database.Groundhog.Core import Database.Groundhog.Generic (isSimple) import Database.Groundhog.Instances ()-import qualified Blaze.ByteString.Builder.Char.Utf8 as B+import qualified Data.Text.Lazy.Builder as B import Data.Maybe (mapMaybe, maybeToList)-#if !(MIN_VERSION_base(4,8,0))-import Data.Monoid hiding ((<>))-#endif import Data.String+import Data.Semigroup (Semigroup(..))  import Database.Groundhog.Expression --- rely on semigroups package providing Semigroup prior to base-4.9-import Data.Semigroup as Sem -class (Sem.Semigroup a, Monoid a, IsString a) => StringLike a where+class (Semigroup a, Monoid a, IsString a) => StringLike a where   fromChar :: Char -> a  data RenderS db r = RenderS {@@ -62,20 +58,8 @@   , getValues :: [PersistValue] -> [PersistValue] } -instance Sem.Semigroup Utf8 where-  (Utf8 a) <> (Utf8 b) = Utf8 (a <> b)--instance Monoid Utf8 where-  mempty = Utf8 mempty-#if !(MIN_VERSION_base(4,11,0))-  mappend = (<>)-#endif--instance IsString Utf8 where-  fromString = Utf8 . B.fromString- instance StringLike Utf8 where-  fromChar = Utf8 . B.fromChar+  fromChar = Utf8 . B.singleton  -- | Escape function, priority of the outer operator. The result is a list for the embedded data which may expand to several RenderS. newtype Snippet db r = Snippet (RenderConfig -> Int -> [RenderS db r])@@ -147,7 +131,7 @@ renderPersistValue (PersistCustom s as) = RenderS s (as++) renderPersistValue a = RenderS (fromChar '?') (a:) -instance Sem.Semigroup (RenderS db r) where+instance Semigroup (RenderS db r) where   (RenderS f1 g1) <> (RenderS f2 g2) = RenderS (f1 <> f2) (g1 . g2)  instance Monoid (RenderS db r) where@@ -162,7 +146,7 @@ instance StringLike (RenderS db r) where   fromChar c = RenderS (fromChar c) id --- Has bad performance. This instance exists only for testing purposes+-- Has bad performance. This instance exists for testing purposes and migration instance StringLike String where   fromChar c = [c] @@ -182,11 +166,6 @@   proxy = undefined :: proxy db   typ = dbType proxy (undefined :: a) -#if !MIN_VERSION_base(4, 5, 0)-{-# INLINABLE (<>) #-}-(<>) :: Monoid m => m -> m -> m-(<>) = mappend-#endif  {-# INLINABLE renderCond #-} -- | Renders conditions for SQL backend. Returns Nothing if the fields don't have any columns.
Database/Groundhog/Instances.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE TypeFamilies, GADTs, TypeSynonymInstances, OverlappingInstances, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, CPP, ConstraintKinds #-}+{-# LANGUAGE TypeFamilies, GADTs, TypeSynonymInstances, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, CPP, ConstraintKinds #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Database.Groundhog.Instances (Selector(..)) where @@ -10,11 +10,7 @@ import qualified Data.Text.Lazy as TL import qualified Data.Text.Encoding as T import qualified Data.Text.Encoding.Error as T-#if MIN_VERSION_base(4, 7, 0) import Data.Bits (finiteBitSize)-#else-import Data.Bits (bitSize)-#endif import Data.ByteString.Char8 (ByteString, unpack) import qualified Data.ByteString.Lazy.Char8 as Lazy import qualified Data.ByteString.Base64 as B64@@ -249,11 +245,11 @@   toPrimitivePersistValue (KeyForBackend a) = toPrimitivePersistValue a   fromPrimitivePersistValue x = KeyForBackend (fromPrimitivePersistValue x) -instance (PersistField a, PrimitivePersistField a) => PurePersistField a where+instance {-# OVERLAPPABLE #-} (PersistField a, PrimitivePersistField a) => PurePersistField a where   toPurePersistValues = primToPurePersistValues   fromPurePersistValues = primFromPurePersistValues -instance (PersistField a, PrimitivePersistField a) => SinglePersistField a where+instance {-# OVERLAPPABLE #-} (PersistField a, PrimitivePersistField a) => SinglePersistField a where   toSinglePersistValue = primToSinglePersistValue   fromSinglePersistValue = primFromSinglePersistValue @@ -438,7 +434,7 @@       DbEmbedded (EmbeddedDef concatName [(field, DbTypePrimitive t True def ref')]) ref     t -> error $ "dbType " ++ persistName a ++ ": expected DbTypePrimitive or DbEmbedded with one field, got " ++ show t -instance (PersistField a) => PersistField [a] where+instance {-# OVERLAPPABLE #-} (PersistField a) => PersistField [a] where   persistName a = "List" ++ delim : delim : persistName ((undefined :: [] a -> a) a)   toPersistValues l = insertList l >>= toPersistValues   fromPersistValues [] = fail "fromPersistValues []: empty list"
changelog view
@@ -1,3 +1,7 @@+0.11+* Suppport for GHC 8.8+* Drop support for GHC 7.*+ 0.10 * Pass type information along the UntypedExpr * Fix #57 (table indexes are ignored)
groundhog.cabal view
@@ -1,11 +1,11 @@ name:            groundhog-version:         0.10.0+version:         0.11.0 license:         BSD3 license-file:    LICENSE author:          Boris Lykah <lykahb@gmail.com> maintainer:      Boris Lykah <lykahb@gmail.com> synopsis:        Type-safe datatype-database mapping library.-description:     This library maps your datatypes to a relational model, in a way similar to what ORM libraries do in object-oriented programming. The mapping can be configured to work with almost any schema. Groundhog supports schema migrations, composite keys, advanced expressions in queries, and much more. See tutorial <https://www.fpcomplete.com/user/lykahb/groundhog> and examples <https://github.com/lykahb/groundhog/tree/master/examples> on GitHub.+description:     This library maps your datatypes to a relational model, in a way similar to what ORM libraries do in object-oriented programming. The mapping can be configured to work with almost any schema. Groundhog supports schema migrations, composite keys, advanced expressions in queries, and much more. See tutorial <https://www.schoolofhaskell.com/user/lykahb/groundhog> and examples <https://github.com/lykahb/groundhog/tree/master/examples> on GitHub. category:        Database stability:       Stable cabal-version:   >= 1.6@@ -26,7 +26,6 @@                    , aeson                    >= 0.5                    , scientific                    , text                     >= 0.8-                   , blaze-builder            >= 0.3        && < 0.5                    , containers               >= 0.2                    , monad-control            >= 0.3        && < 1.1                    , transformers-base