@@ -104,7 +104,7 @@ import Squeal.PostgreSQL.Schema
104statements
104statements
105-----------------------------------------}
105-----------------------------------------}
107−-- | A `Definition` is a statement that changes the schema of the
107+-- | A `Definition` is a statement that changes the schemas of the
108-- database, like a `createTable`, `dropTable`, or `alterTable` command.
108-- database, like a `createTable`, `dropTable`, or `alterTable` command.
109-- `Definition`s may be composed using the `>>>` operator.
109-- `Definition`s may be composed using the `>>>` operator.
110newtype Definition
110newtype Definition
@@ -219,7 +219,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
219 renderCommaSeparated renderConstraint constraints ) )
219 renderCommaSeparated renderConstraint constraints ) )
222− renderColumnDef :: Aliased (ColumnTypeExpression schema) x -> ByteString
222+ renderColumnDef :: Aliased (ColumnTypeExpression db) x -> ByteString
223 renderColumnDef (ty `As` column) =
223 renderColumnDef (ty `As` column) =
224 renderAlias column <+> renderColumnTypeExpression ty
224 renderAlias column <+> renderColumnTypeExpression ty
225 renderConstraint
225 renderConstraint
@@ -741,8 +741,8 @@ newtype AlterColumn (db :: DBType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
742-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
742-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
743setDefault
743setDefault
744− :: Expression schema '[] 'Ungrouped '[] ty -- ^ default value to set
744+ :: Expression db '[] 'Ungrouped '[] ty -- ^ default value to set
745− -> AlterColumn schema (constraint :=> ty) ('Def :=> ty)
745+ -> AlterColumn db (constraint :=> ty) ('Def :=> ty)
746setDefault expression = UnsafeAlterColumn $
746setDefault expression = UnsafeAlterColumn $
747 "SET DEFAULT" <+> renderExpression expression
747 "SET DEFAULT" <+> renderExpression expression
@@ -757,7 +757,7 @@ setDefault expression = UnsafeAlterColumn $
757-- in printSQL definition
757-- in printSQL definition
759-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
759-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
760−dropDefault :: AlterColumn schema ('Def :=> ty) ('NoDef :=> ty)
760+dropDefault :: AlterColumn db ('Def :=> ty) ('NoDef :=> ty)
761dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
761dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
763-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
763-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
@@ -774,7 +774,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
775-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
775-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
776setNotNull
776setNotNull
777− :: AlterColumn schema (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
777+ :: AlterColumn db (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
778setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
778setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
780-- | A `dropNotNull` drops a @NOT NULL@ constraint from a column.
780-- | A `dropNotNull` drops a @NOT NULL@ constraint from a column.
@@ -789,7 +789,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
790-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
790-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
791dropNotNull
791dropNotNull
792− :: AlterColumn schema (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
792+ :: AlterColumn db (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
793dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
793dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
795-- | An `alterType` converts a column to a different data type.
795-- | An `alterType` converts a column to a different data type.
@@ -806,7 +806,7 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
806-- in printSQL definition
806-- in printSQL definition
808-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
808-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
809−alterType :: ColumnTypeExpression schema ty -> AlterColumn schema ty0 ty
809+alterType :: ColumnTypeExpression db ty -> AlterColumn db ty0 ty
810alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
810alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
812-- | Create a view.
812-- | Create a view.
@@ -823,7 +823,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
824-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
824-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
825createView
825createView
826− :: (KnownSymbol sch, KnownSymbol vw)
826+ :: (KnownSymbol sch, KnownSymbol vw, Has sch db schema)
827 => QualifiedAlias sch vw -- ^ the name of the view to add
827 => QualifiedAlias sch vw -- ^ the name of the view to add
828 -> Query db '[] view
828 -> Query db '[] view
829 -- ^ query
829 -- ^ query
@@ -913,7 +913,7 @@ createTypeComposite ty fields = UnsafeDefinition $
913 "CREATE" <+> "TYPE" <+> renderQualifiedAlias ty <+> "AS" <+> parenthesized
913 "CREATE" <+> "TYPE" <+> renderQualifiedAlias ty <+> "AS" <+> parenthesized
914 (renderCommaSeparated renderField fields) <> ";"
914 (renderCommaSeparated renderField fields) <> ";"
916− renderField :: Aliased (TypeExpression schema) x -> ByteString
916+ renderField :: Aliased (TypeExpression db) x -> ByteString
917 renderField (typ `As` alias) =
917 renderField (typ `As` alias) =
918 renderAlias alias <+> renderTypeExpression typ
918 renderAlias alias <+> renderTypeExpression typ
@@ -936,10 +936,10 @@ createTypeCompositeFrom ty = createTypeComposite ty
936 (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped db)) fieldtype
936 (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped db)) fieldtype
937 :: NP (Aliased (TypeExpression db)) (RowPG hask))
937 :: NP (Aliased (TypeExpression db)) (RowPG hask))
939−class FieldTyped schema ty where
939+class FieldTyped db ty where
940− fieldtype :: Aliased (TypeExpression schema) ty
940+ fieldtype :: Aliased (TypeExpression db) ty
941−instance (KnownSymbol alias, PGTyped schema ty)
941+instance (KnownSymbol alias, PGTyped db ty)
942− => FieldTyped schema (alias ::: ty) where
942+ => FieldTyped db (alias ::: ty) where
943 fieldtype = pgtype `As` Alias
943 fieldtype = pgtype `As` Alias
945-- | Drop a type.
945-- | Drop a type.
@@ -971,33 +971,33 @@ nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
971-- | used in `createTable` commands as a column constraint to ensure
971-- | used in `createTable` commands as a column constraint to ensure
972-- @NULL@ is not present in a column
972-- @NULL@ is not present in a column
973notNullable
973notNullable
974− :: TypeExpression schema (nullity ty)
974+ :: TypeExpression db (nullity ty)
975− -> ColumnTypeExpression schema ('NoDef :=> 'NotNull ty)
975+ -> ColumnTypeExpression db ('NoDef :=> 'NotNull ty)
976notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
976notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
978-- | used in `createTable` commands as a column constraint to give a default
978-- | used in `createTable` commands as a column constraint to give a default
980− :: Expression schema '[] 'Ungrouped '[] ty
980+ :: Expression db '[] 'Ungrouped '[] ty
981− -> ColumnTypeExpression schema ('NoDef :=> ty)
981+ -> ColumnTypeExpression db ('NoDef :=> ty)
982− -> ColumnTypeExpression schema ('Def :=> ty)
982+ -> ColumnTypeExpression db ('Def :=> ty)
983default_ x ty = UnsafeColumnTypeExpression $
983default_ x ty = UnsafeColumnTypeExpression $
984 renderColumnTypeExpression ty <+> "DEFAULT" <+> renderExpression x
984 renderColumnTypeExpression ty <+> "DEFAULT" <+> renderExpression x
986-- | not a true type, but merely a notational convenience for creating
986-- | not a true type, but merely a notational convenience for creating
987-- unique identifier columns with type `PGint2`
987-- unique identifier columns with type `PGint2`
988serial2, smallserial
988serial2, smallserial
989− :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint2)
989+ :: ColumnTypeExpression db ('Def :=> 'NotNull 'PGint2)
990serial2 = UnsafeColumnTypeExpression "serial2"
990serial2 = UnsafeColumnTypeExpression "serial2"
991smallserial = UnsafeColumnTypeExpression "smallserial"
991smallserial = UnsafeColumnTypeExpression "smallserial"
992-- | not a true type, but merely a notational convenience for creating
992-- | not a true type, but merely a notational convenience for creating
993-- unique identifier columns with type `PGint4`
993-- unique identifier columns with type `PGint4`
994serial4, serial
994serial4, serial
995− :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint4)
995+ :: ColumnTypeExpression db ('Def :=> 'NotNull 'PGint4)
996serial4 = UnsafeColumnTypeExpression "serial4"
996serial4 = UnsafeColumnTypeExpression "serial4"
997serial = UnsafeColumnTypeExpression "serial"
997serial = UnsafeColumnTypeExpression "serial"
998-- | not a true type, but merely a notational convenience for creating
998-- | not a true type, but merely a notational convenience for creating
999-- unique identifier columns with type `PGint8`
999-- unique identifier columns with type `PGint8`
1000serial8, bigserial
1000serial8, bigserial
1001− :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint8)
1001+ :: ColumnTypeExpression db ('Def :=> 'NotNull 'PGint8)
1002serial8 = UnsafeColumnTypeExpression "serial8"
1002serial8 = UnsafeColumnTypeExpression "serial8"
1003bigserial = UnsafeColumnTypeExpression "bigserial"
1003bigserial = UnsafeColumnTypeExpression "bigserial"