groundhog 0.9.0 → 0.10.0
raw patch · 6 files changed
+96/−46 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Database.Groundhog.Core: instance (db' ~ db) => Database.Groundhog.Core.HasSelectOptions (Database.Groundhog.Core.Cond db r) db' r
- Database.Groundhog.Core: instance (db' ~ db) => Database.Groundhog.Core.HasSelectOptions (Database.Groundhog.Core.SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) db' r
- Database.Groundhog.Expression: instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.RestrictionHolder v c ~ r') => Database.Groundhog.Expression.Expression db r' (Database.Groundhog.Core.Field v c a)
- Database.Groundhog.Expression: instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistField a, db' ~ db, Database.Groundhog.Core.RestrictionHolder v c ~ r') => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.SubField db v c a)
- Database.Groundhog.Expression: instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.RestrictionHolder v c ~ r') => Database.Groundhog.Expression.Expression db r' (Database.Groundhog.Core.AutoKeyField v c)
- Database.Groundhog.Expression: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.IsUniqueKey k, k ~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u), Database.Groundhog.Core.RestrictionHolder v c ~ r') => Database.Groundhog.Expression.Expression db r' (u (Database.Groundhog.Core.UniqueMarker v))
- Database.Groundhog.Expression: instance (Database.Groundhog.Core.PersistField a, db' ~ db, r' ~ r) => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.Expr db r a)
- Database.Groundhog.Expression: instance (Database.Groundhog.Expression.TypeEq (Database.Groundhog.Core.DefaultKey v) (Database.Groundhog.Core.Key v u) isDef, Database.Groundhog.Expression.NormalizeKey isDef v u k, r ~ (Database.Groundhog.Expression.Not isDef, GHC.Base.Maybe k)) => Database.Groundhog.Expression.NormalizeValue (GHC.Base.Maybe (Database.Groundhog.Core.Key v u)) r
- Database.Groundhog.Expression: instance (Database.Groundhog.Expression.TypeEq (Database.Groundhog.Core.DefaultKey v) (Database.Groundhog.Core.Key v u) isDef, Database.Groundhog.Expression.NormalizeKey isDef v u k, r ~ (Database.Groundhog.Expression.Not isDef, k)) => Database.Groundhog.Expression.NormalizeValue (Database.Groundhog.Core.Key v u) r
- Database.Groundhog.Expression: instance (b ~ Database.Groundhog.Core.HFalse) => Database.Groundhog.Expression.TypeEq x y b
- Database.Groundhog.Expression: instance (db' ~ db, r' ~ r) => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.Cond db r)
- Database.Groundhog.Expression: instance (k ~ Database.Groundhog.Core.Key v u) => Database.Groundhog.Expression.NormalizeKey Database.Groundhog.Core.HFalse v u k
- Database.Groundhog.Expression: instance (k ~ v) => Database.Groundhog.Expression.NormalizeKey Database.Groundhog.Core.HTrue v u k
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HFalse, Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u))) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (u (Database.Groundhog.Core.UniqueMarker v)) r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HFalse, Database.Groundhog.Core.Key v Database.Groundhog.Core.BackendSpecific)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.AutoKeyField v c) r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Expr db r' a) r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Field v c a) r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.SubField db v c a) r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HTrue, GHC.Types.Bool)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.Cond db r') r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HTrue, GHC.Types.Bool)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Cond db r') r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HTrue, a)) => Database.Groundhog.Expression.NormalizeValue a r
- Database.Groundhog.Expression: instance (r ~ (Database.Groundhog.Core.HTrue, t)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue t r
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.EntityConstr v c, a ~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.Assignable (Database.Groundhog.Core.AutoKeyField v c) a
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.EntityConstr v c, a ~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.FieldLike (Database.Groundhog.Core.AutoKeyField v c) a
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.EntityConstr v c, a ~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.AutoKeyField v c) a
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k ~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.Assignable (u (Database.Groundhog.Core.UniqueMarker v)) k
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k ~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.FieldLike (u (Database.Groundhog.Core.UniqueMarker v)) k
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k ~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.Projection (u (Database.Groundhog.Core.UniqueMarker v)) k
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.NeverNull a) => Database.Groundhog.Core.PersistField (GHC.Base.Maybe a)
- Database.Groundhog.Instances: instance (Database.Groundhog.Core.PrimitivePersistField a, Database.Groundhog.Core.NeverNull a) => Database.Groundhog.Core.PrimitivePersistField (GHC.Base.Maybe a)
- Database.Groundhog.Instances: instance (a ~ GHC.Types.Bool) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.Cond db r) a
+ Database.Groundhog: data family Selector v :: * -> *
+ Database.Groundhog.Core: -- can be RenderS for relational databases, or BSON for MongoDB.
+ Database.Groundhog.Core: -- datatype v. Each constructor in <a>Field</a> corresponds to its field
+ Database.Groundhog.Core: -- does not have such key, AutoKey v = ().
+ Database.Groundhog.Core: -- field value type.
+ Database.Groundhog.Core: -- has Int64
+ Database.Groundhog.Core: -- in a datatype v. It is parametrised by constructor phantom type and
+ Database.Groundhog.Core: -- primary key, a constraint or unique indices. The second parameter is
+ Database.Groundhog.Core: -- the key description.
+ Database.Groundhog.Core: -- | Value of this type can be used as a part of a query. For example, it
+ Database.Groundhog.Core: instance (db' Data.Type.Equality.~ db) => Database.Groundhog.Core.HasSelectOptions (Database.Groundhog.Core.Cond db r) db' r
+ Database.Groundhog.Core: instance (db' Data.Type.Equality.~ db) => Database.Groundhog.Core.HasSelectOptions (Database.Groundhog.Core.SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) db' r
+ Database.Groundhog.Expression: instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db r' (Database.Groundhog.Core.Field v c a)
+ Database.Groundhog.Expression: instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.PersistField a, db' Data.Type.Equality.~ db, Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.SubField db v c a)
+ Database.Groundhog.Expression: instance (Database.Groundhog.Core.EntityConstr v c, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db r' (Database.Groundhog.Core.AutoKeyField v c)
+ Database.Groundhog.Expression: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.DbDescriptor db, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u), Database.Groundhog.Core.RestrictionHolder v c Data.Type.Equality.~ r') => Database.Groundhog.Expression.Expression db r' (u (Database.Groundhog.Core.UniqueMarker v))
+ Database.Groundhog.Expression: instance (Database.Groundhog.Core.PersistField a, db' Data.Type.Equality.~ db, r' Data.Type.Equality.~ r) => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.Expr db r a)
+ Database.Groundhog.Expression: instance (Database.Groundhog.Expression.TypeEq (Database.Groundhog.Core.DefaultKey v) (Database.Groundhog.Core.Key v u) isDef, Database.Groundhog.Expression.NormalizeKey isDef v u k, r Data.Type.Equality.~ (Database.Groundhog.Expression.Not isDef, GHC.Maybe.Maybe k)) => Database.Groundhog.Expression.NormalizeValue (GHC.Maybe.Maybe (Database.Groundhog.Core.Key v u)) r
+ Database.Groundhog.Expression: instance (Database.Groundhog.Expression.TypeEq (Database.Groundhog.Core.DefaultKey v) (Database.Groundhog.Core.Key v u) isDef, Database.Groundhog.Expression.NormalizeKey isDef v u k, r Data.Type.Equality.~ (Database.Groundhog.Expression.Not isDef, k)) => Database.Groundhog.Expression.NormalizeValue (Database.Groundhog.Core.Key v u) r
+ Database.Groundhog.Expression: instance (b Data.Type.Equality.~ Database.Groundhog.Core.HFalse) => Database.Groundhog.Expression.TypeEq x y b
+ Database.Groundhog.Expression: instance (db' Data.Type.Equality.~ db, r' Data.Type.Equality.~ r) => Database.Groundhog.Expression.Expression db' r' (Database.Groundhog.Core.Cond db r)
+ Database.Groundhog.Expression: instance (k Data.Type.Equality.~ Database.Groundhog.Core.Key v u) => Database.Groundhog.Expression.NormalizeKey Database.Groundhog.Core.HFalse v u k
+ Database.Groundhog.Expression: instance (k Data.Type.Equality.~ v) => Database.Groundhog.Expression.NormalizeKey Database.Groundhog.Core.HTrue v u k
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u))) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (u (Database.Groundhog.Core.UniqueMarker v)) r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, Database.Groundhog.Core.Key v Database.Groundhog.Core.BackendSpecific)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.AutoKeyField v c) r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Expr db r' a) r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Field v c a) r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HFalse, a)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.SubField db v c a) r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, GHC.Types.Bool)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HFalse (Database.Groundhog.Core.Cond db r') r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, GHC.Types.Bool)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue (Database.Groundhog.Core.Cond db r') r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, a)) => Database.Groundhog.Expression.NormalizeValue a r
+ Database.Groundhog.Expression: instance (r Data.Type.Equality.~ (Database.Groundhog.Core.HTrue, t)) => Database.Groundhog.Expression.Normalize Database.Groundhog.Core.HTrue t r
+ Database.Groundhog.Instances: data family Selector v :: * -> *
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.EntityConstr v c, a Data.Type.Equality.~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.Assignable (Database.Groundhog.Core.AutoKeyField v c) a
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.EntityConstr v c, a Data.Type.Equality.~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.FieldLike (Database.Groundhog.Core.AutoKeyField v c) a
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.EntityConstr v c, a Data.Type.Equality.~ Database.Groundhog.Core.AutoKey v) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.AutoKeyField v c) a
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.Assignable (u (Database.Groundhog.Core.UniqueMarker v)) k
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.FieldLike (u (Database.Groundhog.Core.UniqueMarker v)) k
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistEntity v, Database.Groundhog.Core.IsUniqueKey k, k Data.Type.Equality.~ Database.Groundhog.Core.Key v (Database.Groundhog.Core.Unique u)) => Database.Groundhog.Core.Projection (u (Database.Groundhog.Core.UniqueMarker v)) k
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.PersistField a, Database.Groundhog.Core.NeverNull a) => Database.Groundhog.Core.PersistField (GHC.Maybe.Maybe a)
+ Database.Groundhog.Instances: instance (Database.Groundhog.Core.PrimitivePersistField a, Database.Groundhog.Core.NeverNull a) => Database.Groundhog.Core.PrimitivePersistField (GHC.Maybe.Maybe a)
+ Database.Groundhog.Instances: instance (a Data.Type.Equality.~ GHC.Types.Bool) => Database.Groundhog.Core.Projection (Database.Groundhog.Core.Cond db r) a
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.NeverNull Data.Aeson.Types.Internal.Value
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PersistField Data.Aeson.Types.Internal.Value
+ Database.Groundhog.Instances: instance Database.Groundhog.Core.PrimitivePersistField Data.Aeson.Types.Internal.Value
- Database.Groundhog: And :: (Cond db r) -> (Cond db r) -> Cond db r
+ Database.Groundhog: And :: Cond db r -> Cond db r -> Cond db r
- Database.Groundhog: Compare :: ExprRelation -> (UntypedExpr db r) -> (UntypedExpr db r) -> Cond db r
+ Database.Groundhog: Compare :: ExprRelation -> UntypedExpr db r -> UntypedExpr db r -> Cond db r
- Database.Groundhog: CondRaw :: (QueryRaw db r) -> Cond db r
+ Database.Groundhog: CondRaw :: QueryRaw db r -> Cond db r
- Database.Groundhog: Not :: (Cond db r) -> Cond db r
+ Database.Groundhog: Not :: Cond db r -> Cond db r
- Database.Groundhog: Or :: (Cond db r) -> (Cond db r) -> Cond db r
+ Database.Groundhog: Or :: Cond db r -> Cond db r -> Cond db r
- Database.Groundhog: migrate :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration (m)
+ Database.Groundhog: migrate :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration m
- Database.Groundhog: type family Conn m;
+ Database.Groundhog: type family AutoKey v
- Database.Groundhog.Core: And :: (Cond db r) -> (Cond db r) -> Cond db r
+ Database.Groundhog.Core: And :: Cond db r -> Cond db r -> Cond db r
- Database.Groundhog.Core: Compare :: ExprRelation -> (UntypedExpr db r) -> (UntypedExpr db r) -> Cond db r
+ Database.Groundhog.Core: Compare :: ExprRelation -> UntypedExpr db r -> UntypedExpr db r -> Cond db r
- Database.Groundhog.Core: CondRaw :: (QueryRaw db r) -> Cond db r
+ Database.Groundhog.Core: CondRaw :: QueryRaw db r -> Cond db r
- Database.Groundhog.Core: DbEmbedded :: EmbeddedDef -> (Maybe ParentTableReference) -> DbType
+ Database.Groundhog.Core: DbEmbedded :: EmbeddedDef -> Maybe ParentTableReference -> DbType
- Database.Groundhog.Core: DbOther :: (OtherTypeDef' str) -> DbTypePrimitive' str
+ Database.Groundhog.Core: DbOther :: OtherTypeDef' str -> DbTypePrimitive' str
- Database.Groundhog.Core: DbTypePrimitive :: DbTypePrimitive -> Bool -> (Maybe String) -> (Maybe ParentTableReference) -> DbType
+ Database.Groundhog.Core: DbTypePrimitive :: DbTypePrimitive -> Bool -> Maybe String -> Maybe ParentTableReference -> DbType
- Database.Groundhog.Core: Expr :: (UntypedExpr db r) -> Expr db r a
+ Database.Groundhog.Core: Expr :: UntypedExpr db r -> Expr db r a
- Database.Groundhog.Core: KeyForBackend :: (AutoKeyType db) -> KeyForBackend db v
+ Database.Groundhog.Core: KeyForBackend :: AutoKeyType db -> KeyForBackend db v
- Database.Groundhog.Core: Not :: (Cond db r) -> Cond db r
+ Database.Groundhog.Core: Not :: Cond db r -> Cond db r
- Database.Groundhog.Core: Or :: (Cond db r) -> (Cond db r) -> Cond db r
+ Database.Groundhog.Core: Or :: Cond db r -> Cond db r -> Cond db r
- Database.Groundhog.Core: OtherTypeDef :: ([Either str (DbTypePrimitive' str)]) -> OtherTypeDef' str
+ Database.Groundhog.Core: OtherTypeDef :: [Either str (DbTypePrimitive' str)] -> OtherTypeDef' str
- Database.Groundhog.Core: Update :: f -> (UntypedExpr db r) -> Update db r
+ Database.Groundhog.Core: Update :: f -> UntypedExpr db r -> Update db r
- Database.Groundhog.Core: [ExprRaw] :: QueryRaw db r -> UntypedExpr db r
+ Database.Groundhog.Core: [ExprRaw] :: DbType -> QueryRaw db r -> UntypedExpr db r
- Database.Groundhog.Core: migrate :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration (m)
+ Database.Groundhog.Core: migrate :: (PersistBackendConn conn, PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration m
- Database.Groundhog.Core: toPurePersistValues :: PurePersistField a => a -> ([PersistValue] -> [PersistValue])
+ Database.Groundhog.Core: toPurePersistValues :: PurePersistField a => a -> [PersistValue] -> [PersistValue]
- Database.Groundhog.Generic: primToPurePersistValues :: PrimitivePersistField a => a -> ([PersistValue] -> [PersistValue])
+ Database.Groundhog.Generic: primToPurePersistValues :: PrimitivePersistField a => a -> [PersistValue] -> [PersistValue]
- Database.Groundhog.Generic.Migration: AddTriggerOnUpdate :: QualifiedName -> QualifiedName -> (Maybe String) -> String -> AlterDB
+ Database.Groundhog.Generic.Migration: AddTriggerOnUpdate :: QualifiedName -> QualifiedName -> Maybe String -> String -> AlterDB
- Database.Groundhog.Generic.Migration: MigrationPack :: DbTypePrimitive -> DbTypePrimitive -> Bool -> (Maybe String, Reference) -> (Maybe String, Reference) -> Bool -> UniqueDefInfo -> UniqueDefInfo -> Bool -> String -> String -> Bool -> QualifiedName -> [(String, String)] -> Action conn (Bool, [AlterDB]) -> QualifiedName -> [(String, String)] -> Action conn [(Bool, [AlterDB])] -> EntityDef -> ConstructorDef -> Action conn (Bool, SingleMigration) -> String -> String -> String -> String -> Int -> [UniqueDefInfo] -> [Reference] -> ([String], [AlterTable]) -> DbTypePrimitive -> String -> Column -> String -> AlterDB -> SingleMigration -> ReferenceActionType -> ReferenceActionType -> MigrationPack conn
+ Database.Groundhog.Generic.Migration: MigrationPack :: (DbTypePrimitive -> DbTypePrimitive -> Bool) -> ((Maybe String, Reference) -> (Maybe String, Reference) -> Bool) -> (UniqueDefInfo -> UniqueDefInfo -> Bool) -> (String -> String -> Bool) -> (QualifiedName -> [(String, String)] -> Action conn (Bool, [AlterDB])) -> (QualifiedName -> [(String, String)] -> Action conn [(Bool, [AlterDB])]) -> (EntityDef -> ConstructorDef -> Action conn (Bool, SingleMigration)) -> (String -> String) -> String -> String -> Int -> ([UniqueDefInfo] -> [Reference] -> ([String], [AlterTable])) -> (DbTypePrimitive -> String) -> (Column -> String) -> (AlterDB -> SingleMigration) -> ReferenceActionType -> ReferenceActionType -> MigrationPack conn
- Database.Groundhog.Generic.Sql: RenderConfig :: Utf8 -> Utf8 -> RenderConfig
+ Database.Groundhog.Generic.Sql: RenderConfig :: (Utf8 -> Utf8) -> RenderConfig
- Database.Groundhog.Generic.Sql: RenderS :: Utf8 -> [PersistValue] -> [PersistValue] -> RenderS db r
+ Database.Groundhog.Generic.Sql: RenderS :: Utf8 -> ([PersistValue] -> [PersistValue]) -> RenderS db r
- Database.Groundhog.Generic.Sql: flatten :: StringLike s => (s -> s) -> (String, DbType) -> ([s] -> [s])
+ Database.Groundhog.Generic.Sql: flatten :: StringLike s => (s -> s) -> (String, DbType) -> [s] -> [s]
- Database.Groundhog.Generic.Sql: mkExpr :: SqlDb db => Snippet db r -> Expr db r a
+ Database.Groundhog.Generic.Sql: mkExpr :: forall db r a. (SqlDb db, PersistField a) => Snippet db r -> Expr db r a
- Database.Groundhog.Generic.Sql: prerenderExpr :: SqlDb db => RenderConfig -> Expr db r a -> Expr db r a
+ Database.Groundhog.Generic.Sql: prerenderExpr :: forall db r a. (SqlDb db, PersistField a) => RenderConfig -> Expr db r a -> Expr db r a
Files
- Database/Groundhog/Core.hs +2/−2
- Database/Groundhog/Generic.hs +1/−1
- Database/Groundhog/Generic/Sql.hs +70/−42
- Database/Groundhog/Instances.hs +18/−0
- changelog +4/−0
- groundhog.cabal +1/−1
Database/Groundhog/Core.hs view
@@ -272,7 +272,7 @@ runDbPersist = runReaderT class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where- -- | Type of the database default autoincremented key. For example, Sqlite has Int64+ -- | Type of the database default auto-incremented key. For example, Sqlite has Int64 type AutoKeyType db -- | Value of this type can be used as a part of a query. For example, it can be RenderS for relational databases, or BSON for MongoDB. type QueryRaw db :: * -> *@@ -519,7 +519,7 @@ -- | Used to uniformly represent fields, constants and more complex things, e.g., arithmetic expressions. -- A value should be converted to 'UntypedExpr' for usage in expressions data UntypedExpr db r where- ExprRaw :: QueryRaw db r -> UntypedExpr db r+ ExprRaw :: DbType -> QueryRaw db r -> UntypedExpr db r ExprField :: FieldChain -> UntypedExpr db r ExprPure :: forall db r a . PurePersistField a => a -> UntypedExpr db r ExprCond :: Cond db r -> UntypedExpr db r
Database/Groundhog/Generic.hs view
@@ -2,7 +2,7 @@ -- | This helper module is intended for use by the backend creators module Database.Groundhog.Generic- ( + ( -- * Migration createMigration , executeMigration
Database/Groundhog/Generic/Sql.hs view
@@ -1,10 +1,10 @@-{-# LANGUAGE FlexibleContexts, OverloadedStrings, FlexibleInstances, TypeFamilies, RecordWildCards #-}+{-# LANGUAGE FlexibleContexts, OverloadedStrings, FlexibleInstances, TypeFamilies, RecordWildCards, ScopedTypeVariables#-} {-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | This module defines the functions which are used only for backends creation. module Database.Groundhog.Generic.Sql- ( + ( -- * SQL rendering utilities renderCond , defaultShowPrim@@ -100,8 +100,10 @@ logBase' :: (ExpressionOf db r b a, ExpressionOf db r x a, Floating a) => b -> x -> Expr db r a -- | If we reuse complex expression several times, prerendering it saves time. `RenderConfig` can be obtained with `mkExprWithConf`-prerenderExpr :: SqlDb db => RenderConfig -> Expr db r a -> Expr db r a-prerenderExpr conf (Expr e) = Expr $ ExprRaw $ Snippet $ \_ _ -> prerendered where+prerenderExpr :: forall db r a. (SqlDb db, PersistField a) => RenderConfig -> Expr db r a -> Expr db r a+prerenderExpr conf (Expr e) = Expr $ ExprRaw typ $ Snippet $ \_ _ -> prerendered where+ proxy = undefined :: proxy db+ typ = dbType proxy (undefined :: a) -- Priority of outer operation is not known. Assuming that it is high ensures that parentheses won't be missing. prerendered = renderExprExtended conf maxBound e @@ -120,22 +122,22 @@ renderExprPriority :: SqlDb db => RenderConfig -> Int -> UntypedExpr db r -> RenderS db r renderExprPriority conf p expr = (case expr of- ExprRaw (Snippet f) -> let vals = f conf p in ensureOne vals id+ ExprRaw _ (Snippet f) -> explicitHead (f conf p) ExprField f -> let fs = renderChain conf f []- in ensureOne fs $ \f' -> RenderS f' id+ in RenderS (explicitHead fs) id ExprPure a -> let vals = toPurePersistValues a- in ensureOne (vals []) renderPersistValue+ in renderPersistValue $ explicitHead (vals []) ExprCond a -> case renderCondPriority conf p a of Nothing -> error "renderExprPriority: empty condition" Just x -> x) where- ensureOne :: [a] -> (a -> b) -> b- ensureOne xs f = case xs of- [x] -> f x+ explicitHead :: [a] -> a+ explicitHead xs = case xs of+ [x] -> x xs' -> error $ "renderExprPriority: expected one column field, found " ++ show (length xs') renderExprExtended :: SqlDb db => RenderConfig -> Int -> UntypedExpr db r -> [RenderS db r] renderExprExtended conf p expr = (case expr of- ExprRaw (Snippet f) -> f conf p+ ExprRaw _ (Snippet f) -> f conf p ExprField f -> map (flip RenderS id) $ renderChain conf f [] ExprPure a -> let vals = toPurePersistValues a [] in map renderPersistValue vals@@ -175,8 +177,10 @@ function :: SqlDb db => String -> [UntypedExpr db r] -> Snippet db r function func args = Snippet $ \conf _ -> [fromString func <> fromChar '(' <> commasJoin (map (renderExpr conf) args) <> fromChar ')'] -mkExpr :: SqlDb db => Snippet db r -> Expr db r a-mkExpr = Expr . ExprRaw+mkExpr :: forall db r a . (SqlDb db, PersistField a) => Snippet db r -> Expr db r a+mkExpr snippet = Expr $ ExprRaw typ snippet where+ proxy = undefined :: proxy db+ typ = dbType proxy (undefined :: a) #if !MIN_VERSION_base(4, 5, 0) {-# INLINABLE (<>) #-}@@ -189,11 +193,19 @@ renderCond :: SqlDb db => RenderConfig -> Cond db r -> Maybe (RenderS db r)-renderCond conf cond = renderCondPriority conf 0 cond where+renderCond conf cond = renderCondPriority conf 0 cond +flattenNullables :: DbType -> [Bool]+flattenNullables typ = go typ [] where+ go :: DbType -> [Bool] -> [Bool]+ go typ acc = case typ of+ DbEmbedded (EmbeddedDef _ ts) _ -> foldr go acc $ map snd ts+ DbList _ _ -> False : acc+ DbTypePrimitive _ nullable _ _ -> nullable : acc+ {-# INLINABLE renderCondPriority #-} -- | Renders conditions for SQL backend. Returns Nothing if the fields don't have any columns.-renderCondPriority :: SqlDb db+renderCondPriority :: forall db r . SqlDb db => RenderConfig -> Int -> Cond db r -> Maybe (RenderS db r) renderCondPriority conf@RenderConfig{..} priority cond = go cond priority where@@ -202,25 +214,46 @@ go (Not CondEmpty) _ = Just "(1=0)" -- special case for False go (Not a) p = fmap (\a' -> parens notP p $ "NOT " <> a') $ go a notP go (Compare compOp f1 f2) p = (case compOp of- Eq -> renderComp andP " AND " 37 equalsOperator f1 f2- Ne -> renderComp orP " OR " 50 notEqualsOperator f1 f2+ Eq -> renderCompOps andP " AND " 37 ops f1 f2 where+ ops = map (\isNull -> if isNull then equalsOperator else (\a b -> a <> fromChar '=' <> b)) eitherNullable+ Ne -> renderCompOps andP " OR " 50 ops f1 f2 where+ ops = map (\isNull -> if isNull then notEqualsOperator else (\a b -> a <> "<>" <> b)) eitherNullable Gt -> renderComp orP " OR " 38 (\a b -> a <> fromChar '>' <> b) f1 f2 Lt -> renderComp orP " OR " 38 (\a b -> a <> fromChar '<' <> b) f1 f2 Ge -> renderComp orP " OR " 38 (\a b -> a <> ">=" <> b) f1 f2 Le -> renderComp orP " OR " 38 (\a b -> a <> "<=" <> b) f1 f2) where- renderComp interP interOp opP op expr1 expr2 = result where+ proxy = undefined :: proxy db++ eitherNullable = zipWith (||) (nullables f1) (nullables f2)++ nullables expr = case expr of+ ExprRaw t _ -> flattenNullables t+ ExprField ((_, t), _) -> flattenNullables t+ ExprPure a -> flattenNullables $ dbType proxy a+ ExprCond a -> [False]++ renderZip opP op expr1 expr2 = zipWith op expr1' expr2' where expr1' = renderExprExtended conf opP expr1 expr2' = renderExprExtended conf opP expr2- result = case zipWith op expr1' expr2' of- [] -> Nothing- [clause] -> Just $ parens (opP - 1) p clause -- put lower priority to make parentheses appear when the same operator is nested- clauses -> Just $ parens interP p $ intercalateS interOp clauses++ renderZip3 opP ops expr1 expr2 = zipWith3 (\op e1 e2 -> op e1 e2) ops expr1' expr2' where+ expr1' = renderExprExtended conf opP expr1+ expr2' = renderExprExtended conf opP expr2++ groupComparisons interP interOp opP comparisons = case comparisons of+ [] -> Nothing+ [clause] -> Just $ parens (opP - 1) p clause -- put lower priority to make parentheses appear when the same operator is nested+ clauses -> Just $ parens interP p $ intercalateS interOp clauses++ renderComp interP interOp opP op expr1 expr2 = groupComparisons interP interOp opP $ renderZip opP op expr1 expr2+ renderCompOps interP interOp opP ops expr1 expr2 = groupComparisons interP interOp opP $ renderZip3 opP ops expr1 expr2+ go (CondRaw (Snippet f)) p = case f conf p of [] -> Nothing [a] -> Just a _ -> error "renderCond: cannot render CondRaw with many elements" go CondEmpty _ = Nothing- + notP = 35 andP = 30 orP = 20@@ -235,16 +268,16 @@ {- examples of prefixes-[("val1", DbEmbedded False _), ("val4", EmbeddedDef False _), ("val5", EmbeddedDef False _)] -> "val5$val4$val1"-[("val1", DbEmbedded True _), ("val4", EmbeddedDef False _), ("val5", EmbeddedDef False _)] -> ""-[("val1", DbEmbedded False _), ("val4", EmbeddedDef True _), ("val5", EmbeddedDef False _)] -> "val1"-[("val1", DbEmbedded False _), ("val4", EmbeddedDef True _), ("val5", EmbeddedDef True _)] -> "val1"-[("val1", DbEmbedded False _), ("val4", EmbeddedDef False _), ("val5", EmbeddedDef True _)] -> "val4$val1"+[("val1", EmbeddedDef False _), ("val4", EmbeddedDef False _), ("val5", EmbeddedDef False _)] -> "val5$val4$val1"+[("val1", EmbeddedDef True _), ("val4", EmbeddedDef False _), ("val5", EmbeddedDef False _)] -> ""+[("val1", EmbeddedDef False _), ("val4", EmbeddedDef True _), ("val5", EmbeddedDef False _)] -> "val1"+[("val1", EmbeddedDef False _), ("val4", EmbeddedDef True _), ("val5", EmbeddedDef True _)] -> "val1"+[("val1", EmbeddedDef False _), ("val4", EmbeddedDef False _), ("val5", EmbeddedDef True _)] -> "val4$val1" -} {-# INLINABLE renderChain #-} renderChain :: RenderConfig -> FieldChain -> [Utf8] -> [Utf8] renderChain RenderConfig{..} (f, prefix) acc = (case prefix of- ((name, EmbeddedDef False _):fs) -> flattenP esc (goP (fromString name) fs) f acc+ ((name, EmbeddedDef False _):fs) -> flattenP esc (Just $ goP (fromString name) fs) f acc _ -> flatten esc f acc) where goP p ((name, EmbeddedDef False _):fs) = goP (fromString name <> fromChar delim <> p) fs goP p _ = p@@ -281,26 +314,21 @@ renderFields :: StringLike s => (s -> s) -> [(String, DbType)] -> s renderFields escape = commasJoin . foldr (flatten escape) [] --- TODO: merge code of flatten and flattenP {-# SPECIALIZE flatten :: (Utf8 -> Utf8) -> (String, DbType) -> ([Utf8] -> [Utf8]) #-} flatten :: StringLike s => (s -> s) -> (String, DbType) -> ([s] -> [s])-flatten escape (fname, typ) acc = go typ where- go typ' = case typ' of- DbEmbedded emb _ -> handleEmb emb- _ -> escape fullName : acc- fullName = fromString fname- handleEmb (EmbeddedDef False ts) = foldr (flattenP escape fullName) acc ts- handleEmb (EmbeddedDef True ts) = foldr (flatten escape) acc ts+flatten escape (fname, typ) acc = flattenP escape Nothing (fname, typ) acc -{-# SPECIALIZE flattenP :: (Utf8 -> Utf8) -> Utf8 -> (String, DbType) -> ([Utf8] -> [Utf8]) #-}-flattenP :: StringLike s => (s -> s) -> s -> (String, DbType) -> ([s] -> [s])+{-# SPECIALIZE flattenP :: (Utf8 -> Utf8) -> Maybe Utf8 -> (String, DbType) -> ([Utf8] -> [Utf8]) #-}+flattenP :: StringLike s => (s -> s) -> Maybe s -> (String, DbType) -> ([s] -> [s]) flattenP escape prefix (fname, typ) acc = go typ where go typ' = case typ' of DbEmbedded emb _ -> handleEmb emb _ -> escape fullName : acc- fullName = prefix <> fromChar delim <> fromString fname- handleEmb (EmbeddedDef False ts) = foldr (flattenP escape fullName) acc ts- handleEmb (EmbeddedDef True ts) = foldr (flatten escape) acc ts+ fullName = case prefix of+ Nothing -> fromString fname+ Just prefix -> prefix <> fromChar delim <> fromString fname+ handleEmb (EmbeddedDef False ts) = foldr (flattenP escape (Just fullName)) acc ts+ handleEmb (EmbeddedDef True ts) = foldr (flattenP escape Nothing) acc ts commasJoin :: StringLike s => [s] -> s commasJoin = intercalateS (fromChar ',')
Database/Groundhog/Instances.hs view
@@ -229,6 +229,17 @@ fromPrimitivePersistValue (PersistUTCTime a) = utcToZonedTime utc a fromPrimitivePersistValue x = readHelper x ("Expected ZonedTime, received: " ++ show x) +instance PrimitivePersistField A.Value where+ toPrimitivePersistValue a = PersistByteString $ Lazy.toStrict $ A.encode a+ fromPrimitivePersistValue x = (case x of+ PersistString str -> decode' $ T.encodeUtf8 $ T.pack str+ PersistText str -> decode' $ T.encodeUtf8 str+ PersistByteString str -> decode' str+ _ -> error $ "Expected Aeson.Value, received: " ++ show x) where+ decode' str = case A.eitherDecode $ Lazy.fromStrict str of+ Right val -> val+ Left err -> error $ "Error decoding Aeson.Value: " ++ err+ instance (PrimitivePersistField a, NeverNull a) => PrimitivePersistField (Maybe a) where toPrimitivePersistValue a = maybe PersistNull toPrimitivePersistValue a fromPrimitivePersistValue PersistNull = Nothing@@ -266,6 +277,7 @@ instance NeverNull TimeOfDay instance NeverNull UTCTime instance NeverNull ZonedTime+instance NeverNull A.Value instance PrimitivePersistField (Key v u) => NeverNull (Key v u) instance NeverNull (KeyForBackend db v) @@ -288,6 +300,12 @@ instance PersistField Lazy.ByteString where persistName _ = "ByteString"+ toPersistValues = primToPersistValue+ fromPersistValues = primFromPersistValue+ dbType _ _ = DbTypePrimitive DbBlob False Nothing Nothing++instance PersistField A.Value where+ persistName _ = "JsonValue" toPersistValues = primToPersistValue fromPersistValues = primFromPersistValue dbType _ _ = DbTypePrimitive DbBlob False Nothing Nothing
changelog view
@@ -1,3 +1,7 @@+0.10+* Pass type information along the UntypedExpr+* Fix #57 (table indexes are ignored)+ 0.9.0 * Support for GHC 8.4
groundhog.cabal view
@@ -1,5 +1,5 @@ name: groundhog-version: 0.9.0+version: 0.10.0 license: BSD3 license-file: LICENSE author: Boris Lykah <lykahb@gmail.com>