@@ -110,12 +110,12 @@ statements
110-- database, like a `createTable`, `dropTable`, or `alterTable` command.
110-- database, like a `createTable`, `dropTable`, or `alterTable` command.
111-- `Definition`s may be composed using the `>>>` operator.
111-- `Definition`s may be composed using the `>>>` operator.
112newtype Definition
112newtype Definition
113− (db0 :: DBType)
113+ (schemas0 :: SchemasType)
114− (db1 :: DBType)
114+ (schemas1 :: SchemasType)
115 = UnsafeDefinition { renderDefinition :: ByteString }
115 = UnsafeDefinition { renderDefinition :: ByteString }
116 deriving (GHC.Generic,Show,Eq,Ord,NFData)
116 deriving (GHC.Generic,Show,Eq,Ord,NFData)
118−instance RenderSQL (Definition db0 db1) where
118+instance RenderSQL (Definition schemas0 schemas1) where
119 renderSQL = renderDefinition
119 renderSQL = renderDefinition
121instance Category Definition where
121instance Category Definition where
@@ -130,14 +130,14 @@ CREATE statements
130createSchema
130createSchema
131 :: KnownSymbol sch
131 :: KnownSymbol sch
132 => Alias sch
132 => Alias sch
133− -> Definition db (Create sch '[] db)
133+ -> Definition schemas (Create sch '[] schemas)
134createSchema sch = UnsafeDefinition $
134createSchema sch = UnsafeDefinition $
135 "CREATE" <+> "SCHEMA" <+> renderAlias sch <> ";"
135 "CREATE" <+> "SCHEMA" <+> renderAlias sch <> ";"
137createSchemaIfNotExists
137createSchemaIfNotExists
138− :: (KnownSymbol sch, Has sch db schema)
138+ :: (KnownSymbol sch, Has sch schemas schema)
139 => Alias sch
139 => Alias sch
140− -> Definition db db
140+ -> Definition schemas schemas
141createSchemaIfNotExists sch = UnsafeDefinition $
141createSchemaIfNotExists sch = UnsafeDefinition $
142 "CREATE" <+> "SCHEMA" <+> "IF" <+> "NOT" <+> "EXISTS"
142 "CREATE" <+> "SCHEMA" <+> "IF" <+> "NOT" <+> "EXISTS"
143 <+> renderAlias sch <> ";"
143 <+> renderAlias sch <> ";"
@@ -166,14 +166,14 @@ createTable
166 , columns ~ (col ': cols)
166 , columns ~ (col ': cols)
167 , SOP.SListI columns
167 , SOP.SListI columns
168 , SOP.SListI constraints
168 , SOP.SListI constraints
169− , Has sch db0 schema0
169+ , Has sch schemas0 schema0
170− , db1 ~ Alter sch (Create tab ('Table (constraints :=> columns)) schema0) db0 )
170+ , schemas1 ~ Alter sch (Create tab ('Table (constraints :=> columns)) schema0) schemas0 )
171 => QualifiedAlias sch tab -- ^ the name of the table to add
171 => QualifiedAlias sch tab -- ^ the name of the table to add
172− -> NP (Aliased (ColumnTypeExpression db0)) columns
172+ -> NP (Aliased (ColumnTypeExpression schemas0)) columns
173 -- ^ the names and datatype of each column
173 -- ^ the names and datatype of each column
174− -> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
174+ -> NP (Aliased (TableConstraintExpression sch tab schemas1)) constraints
175 -- ^ constraints that must hold for the table
175 -- ^ constraints that must hold for the table
176− -> Definition db0 db1
176+ -> Definition schemas0 schemas1
177createTable tab columns constraints = UnsafeDefinition $
177createTable tab columns constraints = UnsafeDefinition $
178 "CREATE TABLE" <+> renderCreation tab columns constraints
178 "CREATE TABLE" <+> renderCreation tab columns constraints
@@ -201,16 +201,16 @@ in printSQL setup
201CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
201CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
203createTableIfNotExists
203createTableIfNotExists
204− :: ( Has sch db schema
204+ :: ( Has sch schemas schema
205 , Has tab schema ('Table (constraints :=> columns))
205 , Has tab schema ('Table (constraints :=> columns))
206 , SOP.SListI columns
206 , SOP.SListI columns
207 , SOP.SListI constraints )
207 , SOP.SListI constraints )
208 => QualifiedAlias sch tab -- ^ the name of the table to add
208 => QualifiedAlias sch tab -- ^ the name of the table to add
209− -> NP (Aliased (ColumnTypeExpression db)) columns
209+ -> NP (Aliased (ColumnTypeExpression schemas)) columns
210 -- ^ the names and datatype of each column
210 -- ^ the names and datatype of each column
211− -> NP (Aliased (TableConstraintExpression sch tab db)) constraints
211+ -> NP (Aliased (TableConstraintExpression sch tab schemas)) constraints
212 -- ^ constraints that must hold for the table
212 -- ^ constraints that must hold for the table
213− -> Definition db db
213+ -> Definition schemas schemas
214createTableIfNotExists tab columns constraints = UnsafeDefinition $
214createTableIfNotExists tab columns constraints = UnsafeDefinition $
215 "CREATE TABLE IF NOT EXISTS"
215 "CREATE TABLE IF NOT EXISTS"
216 <+> renderCreation tab columns constraints
216 <+> renderCreation tab columns constraints
@@ -222,9 +222,9 @@ renderCreation
222 , SOP.SListI columns
222 , SOP.SListI columns
223 , SOP.SListI constraints )
223 , SOP.SListI constraints )
224 => QualifiedAlias sch tab -- ^ the name of the table to add
224 => QualifiedAlias sch tab -- ^ the name of the table to add
225− -> NP (Aliased (ColumnTypeExpression db0)) columns
225+ -> NP (Aliased (ColumnTypeExpression schemas0)) columns
226 -- ^ the names and datatype of each column
226 -- ^ the names and datatype of each column
227− -> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
227+ -> NP (Aliased (TableConstraintExpression sch tab schemas1)) constraints
228 -- ^ constraints that must hold for the table
228 -- ^ constraints that must hold for the table
229 -> ByteString
229 -> ByteString
230renderCreation tab columns constraints = renderQualifiedAlias tab
230renderCreation tab columns constraints = renderQualifiedAlias tab
@@ -236,11 +236,11 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
236 renderCommaSeparated renderConstraint constraints ) )
236 renderCommaSeparated renderConstraint constraints ) )
239− renderColumnDef :: Aliased (ColumnTypeExpression db) x -> ByteString
239+ renderColumnDef :: Aliased (ColumnTypeExpression schemas) x -> ByteString
240 renderColumnDef (ty `As` column) =
240 renderColumnDef (ty `As` column) =
241 renderAlias column <+> renderColumnTypeExpression ty
241 renderAlias column <+> renderColumnTypeExpression ty
242 renderConstraint
242 renderConstraint
243− :: Aliased (TableConstraintExpression sch tab db) constraint
243+ :: Aliased (TableConstraintExpression sch tab schemas) constraint
244 -> ByteString
244 -> ByteString
245 renderConstraint (constraint `As` alias) =
245 renderConstraint (constraint `As` alias) =
246 "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
246 "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
@@ -260,7 +260,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
260newtype TableConstraintExpression
260newtype TableConstraintExpression
261 (sch :: Symbol)
261 (sch :: Symbol)
262 (tab :: Symbol)
262 (tab :: Symbol)
263− (db :: DBType)
263+ (schemas :: SchemasType)
264 (constraint :: TableConstraint)
264 (constraint :: TableConstraint)
265 = UnsafeTableConstraintExpression
265 = UnsafeTableConstraintExpression
266 { renderTableConstraintExpression :: ByteString }
266 { renderTableConstraintExpression :: ByteString }
@@ -291,14 +291,14 @@ let
291CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
291CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
294− :: ( Has sch db schema
294+ :: ( Has sch schemas schema
295 , Has tab schema ('Table table)
295 , Has tab schema ('Table table)
296 , HasAll aliases (TableToRow table) subcolumns )
296 , HasAll aliases (TableToRow table) subcolumns )
297 => NP Alias aliases
297 => NP Alias aliases
298 -- ^ specify the subcolumns which are getting checked
298 -- ^ specify the subcolumns which are getting checked
299− -> (forall t. Condition db '[t ::: subcolumns] 'Ungrouped '[])
299+ -> (forall t. Condition ('[] :=> schemas) '[t ::: subcolumns] 'Ungrouped '[])
300 -- ^ a closed `Condition` on those subcolumns
300 -- ^ a closed `Condition` on those subcolumns
301− -> TableConstraintExpression sch tab db ('Check aliases)
301+ -> TableConstraintExpression sch tab schemas ('Check aliases)
302check _cols condition = UnsafeTableConstraintExpression $
302check _cols condition = UnsafeTableConstraintExpression $
303 "CHECK" <+> parenthesized (renderExpression condition)
303 "CHECK" <+> parenthesized (renderExpression condition)
@@ -326,12 +326,12 @@ let
326CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
326CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
329− :: ( Has sch db schema
329+ :: ( Has sch schemas schema
330 , Has tab schema('Table table)
330 , Has tab schema('Table table)
331 , HasAll aliases (TableToRow table) subcolumns )
331 , HasAll aliases (TableToRow table) subcolumns )
332 => NP Alias aliases
332 => NP Alias aliases
333 -- ^ specify subcolumns which together are unique for each row
333 -- ^ specify subcolumns which together are unique for each row
334− -> TableConstraintExpression sch tab db ('Unique aliases)
334+ -> TableConstraintExpression sch tab schemas ('Unique aliases)
335unique columns = UnsafeTableConstraintExpression $
335unique columns = UnsafeTableConstraintExpression $
336 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
336 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
@@ -361,13 +361,13 @@ let
361CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
361CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
363primaryKey
363primaryKey
364− :: ( Has sch db schema
364+ :: ( Has sch schemas schema
365 , Has tab schema ('Table table)
365 , Has tab schema ('Table table)
366 , HasAll aliases (TableToColumns table) subcolumns
366 , HasAll aliases (TableToColumns table) subcolumns
367 , AllNotNull subcolumns )
367 , AllNotNull subcolumns )
368 => NP Alias aliases
368 => NP Alias aliases
369 -- ^ specify the subcolumns which together form a primary key.
369 -- ^ specify the subcolumns which together form a primary key.
370− -> TableConstraintExpression sch tab db ('PrimaryKey aliases)
370+ -> TableConstraintExpression sch tab schemas ('PrimaryKey aliases)
371primaryKey columns = UnsafeTableConstraintExpression $
371primaryKey columns = UnsafeTableConstraintExpression $
372 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
372 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
@@ -445,7 +445,7 @@ in printSQL setup
445CREATE TABLE "employees" ("id" serial, "name" text NOT NULL, "employer_id" integer NULL, CONSTRAINT "employees_pk" PRIMARY KEY ("id"), CONSTRAINT "employees_employer_fk" FOREIGN KEY ("employer_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
445CREATE TABLE "employees" ("id" serial, "name" text NOT NULL, "employer_id" integer NULL, CONSTRAINT "employees_pk" PRIMARY KEY ("id"), CONSTRAINT "employees_employer_fk" FOREIGN KEY ("employer_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
447foreignKey
447foreignKey
448− :: (ForeignKeyed db sch schema child parent
448+ :: (ForeignKeyed schemas sch schema child parent
449 table reftable
449 table reftable
450 columns refcolumns
450 columns refcolumns
451 constraints cols
451 constraints cols
@@ -460,7 +460,7 @@ foreignKey
460 -- ^ what to do when reference is deleted
460 -- ^ what to do when reference is deleted
461 -> OnUpdateClause
461 -> OnUpdateClause
462 -- ^ what to do when reference is updated
462 -- ^ what to do when reference is updated
463− -> TableConstraintExpression sch child db
463+ -> TableConstraintExpression sch child schemas
464 ('ForeignKey columns parent refcolumns)
464 ('ForeignKey columns parent refcolumns)
465foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
465foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
466 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
466 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
@@ -470,7 +470,7 @@ foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
470 <+> renderOnUpdateClause onupd
470 <+> renderOnUpdateClause onupd
472-- | A constraint synonym between types involved in a foreign key constraint.
472-- | A constraint synonym between types involved in a foreign key constraint.
473−type ForeignKeyed db
473+type ForeignKeyed schemas
476 child parent
476 child parent
@@ -478,7 +478,7 @@ type ForeignKeyed db
478 columns refcolumns
478 columns refcolumns
479 constraints cols
479 constraints cols
480 reftys tys =
480 reftys tys =
481− ( Has sch db schema
481+ ( Has sch schemas schema
482 , Has child schema ('Table table)
482 , Has child schema ('Table table)
483 , Has parent schema ('Table reftable)
483 , Has parent schema ('Table reftable)
484 , HasAll columns (TableToColumns table) tys
484 , HasAll columns (TableToColumns table) tys
@@ -541,10 +541,10 @@ DROP statements
541-- >>> printSQL definition
541-- >>> printSQL definition
542-- DROP TABLE "muh_table";
542-- DROP TABLE "muh_table";
544− :: ( Has sch db schema
544+ :: ( Has sch schemas schema
545 , Has tab schema ('Table table))
545 , Has tab schema ('Table table))
546 => QualifiedAlias sch tab -- ^ table to remove
546 => QualifiedAlias sch tab -- ^ table to remove
547− -> Definition db (Alter sch (Drop tab schema) db)
547+ -> Definition schemas (Alter sch (Drop tab schema) schemas)
548dropTable tab = UnsafeDefinition $ "DROP TABLE" <+> renderQualifiedAlias tab <> ";"
548dropTable tab = UnsafeDefinition $ "DROP TABLE" <+> renderQualifiedAlias tab <> ";"
550{-----------------------------------------
550{-----------------------------------------
@@ -553,10 +553,10 @@ ALTER statements
554-- | `alterTable` changes the definition of a table from the schema.
554-- | `alterTable` changes the definition of a table from the schema.
555alterTable
555alterTable
556− :: (Has sch db schema, Has tab schema ('Table table0))
556+ :: (Has sch schemas schema, Has tab schema ('Table table0))
557 => QualifiedAlias sch tab -- ^ table to alter
557 => QualifiedAlias sch tab -- ^ table to alter
558− -> AlterTable sch tab db table1 -- ^ alteration to perform
558+ -> AlterTable sch tab schemas table1 -- ^ alteration to perform
559− -> Definition db (Alter sch (Alter tab ('Table table1) schema) db)
559+ -> Definition schemas (Alter sch (Alter tab ('Table table1) schema) schemas)
560alterTable tab alteration = UnsafeDefinition $
560alterTable tab alteration = UnsafeDefinition $
561 "ALTER TABLE"
561 "ALTER TABLE"
562 <+> renderQualifiedAlias tab
562 <+> renderQualifiedAlias tab
@@ -581,7 +581,7 @@ alterTableRename table0 table1 = UnsafeDefinition $
581newtype AlterTable
581newtype AlterTable
582 (sch :: Symbol)
582 (sch :: Symbol)
583 (tab :: Symbol)
583 (tab :: Symbol)
584− (db :: DBType)
584+ (schemas :: SchemasType)
585 (table :: TableType) =
585 (table :: TableType) =
586 UnsafeAlterTable {renderAlterTable :: ByteString}
586 UnsafeAlterTable {renderAlterTable :: ByteString}
587 deriving (GHC.Generic,Show,Eq,Ord,NFData)
587 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -599,14 +599,14 @@ newtype AlterTable
599-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
599-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
600addConstraint
600addConstraint
601 :: ( KnownSymbol alias
601 :: ( KnownSymbol alias
602− , Has sch db schema
602+ , Has sch schemas schema
603 , Has tab schema ('Table table0)
603 , Has tab schema ('Table table0)
604 , table0 ~ (constraints :=> columns)
604 , table0 ~ (constraints :=> columns)
605 , table1 ~ (Create alias constraint constraints :=> columns) )
605 , table1 ~ (Create alias constraint constraints :=> columns) )
606 => Alias alias
606 => Alias alias
607− -> TableConstraintExpression sch tab db constraint
607+ -> TableConstraintExpression sch tab schemas constraint
608 -- ^ constraint to add
608 -- ^ constraint to add
609− -> AlterTable sch tab db table1
609+ -> AlterTable sch tab schemas table1
610addConstraint alias constraint = UnsafeAlterTable $
610addConstraint alias constraint = UnsafeAlterTable $
611 "ADD" <+> "CONSTRAINT" <+> renderAlias alias
611 "ADD" <+> "CONSTRAINT" <+> renderAlias alias
612 <+> renderTableConstraintExpression constraint
612 <+> renderTableConstraintExpression constraint
@@ -624,13 +624,13 @@ addConstraint alias constraint = UnsafeAlterTable $
624-- ALTER TABLE "tab" DROP CONSTRAINT "positive";
624-- ALTER TABLE "tab" DROP CONSTRAINT "positive";
625dropConstraint
625dropConstraint
626 :: ( KnownSymbol constraint
626 :: ( KnownSymbol constraint
627− , Has sch db schema
627+ , Has sch schemas schema
628 , Has tab schema ('Table table0)
628 , Has tab schema ('Table table0)
629 , table0 ~ (constraints :=> columns)
629 , table0 ~ (constraints :=> columns)
630 , table1 ~ (Drop constraint constraints :=> columns) )
630 , table1 ~ (Drop constraint constraints :=> columns) )
631 => Alias constraint
631 => Alias constraint
632 -- ^ constraint to drop
632 -- ^ constraint to drop
633− -> AlterTable sch tab db table1
633+ -> AlterTable sch tab schemas table1
634dropConstraint constraint = UnsafeAlterTable $
634dropConstraint constraint = UnsafeAlterTable $
635 "DROP" <+> "CONSTRAINT" <+> renderAlias constraint
635 "DROP" <+> "CONSTRAINT" <+> renderAlias constraint
@@ -664,12 +664,12 @@ class AddColumn ty where
664 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
664 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
665 addColumn
665 addColumn
666 :: ( KnownSymbol column
666 :: ( KnownSymbol column
667− , Has sch db schema
667+ , Has sch schemas schema
668 , Has tab schema ('Table table0)
668 , Has tab schema ('Table table0)
669 , table0 ~ (constraints :=> columns) )
669 , table0 ~ (constraints :=> columns) )
670 => Alias column -- ^ column to add
670 => Alias column -- ^ column to add
671− -> ColumnTypeExpression db ty -- ^ type of the new column
671+ -> ColumnTypeExpression schemas ty -- ^ type of the new column
672− -> AlterTable sch tab db (constraints :=> Create column ty columns)
672+ -> AlterTable sch tab schemas (constraints :=> Create column ty columns)
673 addColumn column ty = UnsafeAlterTable $
673 addColumn column ty = UnsafeAlterTable $
674 "ADD COLUMN" <+> renderAlias column <+> renderColumnTypeExpression ty
674 "ADD COLUMN" <+> renderAlias column <+> renderColumnTypeExpression ty
675instance {-# OVERLAPPING #-} AddColumn ('Def :=> ty)
675instance {-# OVERLAPPING #-} AddColumn ('Def :=> ty)
@@ -693,12 +693,12 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
693-- ALTER TABLE "tab" DROP COLUMN "col2";
693-- ALTER TABLE "tab" DROP COLUMN "col2";
694dropColumn
694dropColumn
695 :: ( KnownSymbol column
695 :: ( KnownSymbol column
696− , Has sch db schema
696+ , Has sch schemas schema
697 , Has tab schema ('Table table0)
697 , Has tab schema ('Table table0)
698 , table0 ~ (constraints :=> columns)
698 , table0 ~ (constraints :=> columns)
699 , table1 ~ (constraints :=> Drop column columns) )
699 , table1 ~ (constraints :=> Drop column columns) )
700 => Alias column -- ^ column to remove
700 => Alias column -- ^ column to remove
701− -> AlterTable sch tab db table1
701+ -> AlterTable sch tab schemas table1
702dropColumn column = UnsafeAlterTable $
702dropColumn column = UnsafeAlterTable $
703 "DROP COLUMN" <+> renderAlias column
703 "DROP COLUMN" <+> renderAlias column
@@ -716,32 +716,32 @@ dropColumn column = UnsafeAlterTable $
716renameColumn
716renameColumn
717 :: ( KnownSymbol column0
717 :: ( KnownSymbol column0
718 , KnownSymbol column1
718 , KnownSymbol column1
719− , Has sch db schema
719+ , Has sch schemas schema
720 , Has tab schema ('Table table0)
720 , Has tab schema ('Table table0)
721 , table0 ~ (constraints :=> columns)
721 , table0 ~ (constraints :=> columns)
722 , table1 ~ (constraints :=> Rename column0 column1 columns) )
722 , table1 ~ (constraints :=> Rename column0 column1 columns) )
723 => Alias column0 -- ^ column to rename
723 => Alias column0 -- ^ column to rename
724 -> Alias column1 -- ^ what to rename the column
724 -> Alias column1 -- ^ what to rename the column
725− -> AlterTable sch tab db table1
725+ -> AlterTable sch tab schemas table1
726renameColumn column0 column1 = UnsafeAlterTable $
726renameColumn column0 column1 = UnsafeAlterTable $
727 "RENAME COLUMN" <+> renderAlias column0 <+> "TO" <+> renderAlias column1
727 "RENAME COLUMN" <+> renderAlias column0 <+> "TO" <+> renderAlias column1
729-- | An `alterColumn` alters a single column.
729-- | An `alterColumn` alters a single column.
730alterColumn
730alterColumn
731 :: ( KnownSymbol column
731 :: ( KnownSymbol column
732− , Has sch db schema
732+ , Has sch schemas schema
733 , Has tab schema ('Table table0)
733 , Has tab schema ('Table table0)
734 , table0 ~ (constraints :=> columns)
734 , table0 ~ (constraints :=> columns)
735 , Has column columns ty0
735 , Has column columns ty0
736 , tables1 ~ (constraints :=> Alter column ty1 columns))
736 , tables1 ~ (constraints :=> Alter column ty1 columns))
737 => Alias column -- ^ column to alter
737 => Alias column -- ^ column to alter
738− -> AlterColumn db ty0 ty1 -- ^ alteration to perform
738+ -> AlterColumn schemas ty0 ty1 -- ^ alteration to perform
739− -> AlterTable sch tab db table1
739+ -> AlterTable sch tab schemas table1
740alterColumn column alteration = UnsafeAlterTable $
740alterColumn column alteration = UnsafeAlterTable $
741 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
741 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
743-- | An `AlterColumn` describes the alteration to perform on a single column.
743-- | An `AlterColumn` describes the alteration to perform on a single column.
744−newtype AlterColumn (db :: DBType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
744+newtype AlterColumn (schemas :: SchemasType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
745 UnsafeAlterColumn {renderAlterColumn :: ByteString}
745 UnsafeAlterColumn {renderAlterColumn :: ByteString}
746 deriving (GHC.Generic,Show,Eq,Ord,NFData)
746 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -759,8 +759,8 @@ newtype AlterColumn (db :: DBType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
760-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
760-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
761setDefault
761setDefault
762− :: Expression db '[] 'Ungrouped '[] ty -- ^ default value to set
762+ :: Expression ('[] :=> schemas) '[] 'Ungrouped '[] ty -- ^ default value to set
763− -> AlterColumn db (constraint :=> ty) ('Def :=> ty)
763+ -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
764setDefault expression = UnsafeAlterColumn $
764setDefault expression = UnsafeAlterColumn $
765 "SET DEFAULT" <+> renderExpression expression
765 "SET DEFAULT" <+> renderExpression expression
@@ -775,7 +775,7 @@ setDefault expression = UnsafeAlterColumn $
775-- in printSQL definition
775-- in printSQL definition
777-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
777-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
778−dropDefault :: AlterColumn db ('Def :=> ty) ('NoDef :=> ty)
778+dropDefault :: AlterColumn schemas ('Def :=> ty) ('NoDef :=> ty)
779dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
779dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
781-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
781-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
@@ -792,7 +792,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
793-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
793-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
794setNotNull
794setNotNull
795− :: AlterColumn db (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
795+ :: AlterColumn schemas (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
796setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
796setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
798-- | A `dropNotNull` drops a @NOT NULL@ constraint from a column.
798-- | A `dropNotNull` drops a @NOT NULL@ constraint from a column.
@@ -807,7 +807,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
808-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
808-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
809dropNotNull
809dropNotNull
810− :: AlterColumn db (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
810+ :: AlterColumn schemas (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
811dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
811dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
813-- | An `alterType` converts a column to a different data type.
813-- | An `alterType` converts a column to a different data type.
@@ -824,7 +824,7 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
824-- in printSQL definition
824-- in printSQL definition
826-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
826-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
827−alterType :: ColumnTypeExpression db ty -> AlterColumn db ty0 ty
827+alterType :: ColumnTypeExpression schemas ty -> AlterColumn schemas ty0 ty
828alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
828alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
830{- | Create a view.
830{- | Create a view.
@@ -842,10 +842,10 @@ in printSQL definition
842CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
842CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
844createView
844createView
845− :: (KnownSymbol sch, KnownSymbol vw, Has sch db schema)
845+ :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
846 => QualifiedAlias sch vw -- ^ the name of the view to add
846 => QualifiedAlias sch vw -- ^ the name of the view to add
847− -> Query db '[] view -- ^ query
847+ -> Query ('[] :=> schemas) '[] view -- ^ query
848− -> Definition db (Alter sch (Create vw ('View view) schema) db)
848+ -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
849createView alias query = UnsafeDefinition $
849createView alias query = UnsafeDefinition $
850 "CREATE" <+> "VIEW" <+> renderQualifiedAlias alias <+> "AS"
850 "CREATE" <+> "VIEW" <+> renderQualifiedAlias alias <+> "AS"
851 <+> renderQuery query <> ";"
851 <+> renderQuery query <> ";"
@@ -863,9 +863,9 @@ createView alias query = UnsafeDefinition $
864-- DROP VIEW "bc";
864-- DROP VIEW "bc";
866− :: (Has sch db schema, Has vw schema ('View view))
866+ :: (Has sch schemas schema, Has vw schema ('View view))
867 => QualifiedAlias sch vw -- ^ view to remove
867 => QualifiedAlias sch vw -- ^ view to remove
868− -> Definition db (Alter sch (Drop vw schema) db)
868+ -> Definition schemas (Alter sch (Drop vw schema) schemas)
869dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
869dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
871-- | Enumerated types are created using the `createTypeEnum` command, for example
871-- | Enumerated types are created using the `createTypeEnum` command, for example
@@ -873,12 +873,12 @@ dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
873-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition '["public" ::: '[]] '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
873-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition '["public" ::: '[]] '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
874-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
874-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
875createTypeEnum
875createTypeEnum
876− :: (KnownSymbol enum, Has sch db schema, SOP.All KnownSymbol labels)
876+ :: (KnownSymbol enum, Has sch schemas schema, SOP.All KnownSymbol labels)
877 => QualifiedAlias sch enum
877 => QualifiedAlias sch enum
878 -- ^ name of the user defined enumerated type
878 -- ^ name of the user defined enumerated type
879 -> NP PGlabel labels
879 -> NP PGlabel labels
880 -- ^ labels of the enumerated type
880 -- ^ labels of the enumerated type
881− -> Definition db (Alter sch (Create enum ('Typedef ('PGenum labels)) schema) db)
881+ -> Definition schemas (Alter sch (Create enum ('Typedef ('PGenum labels)) schema) schemas)
882createTypeEnum enum labels = UnsafeDefinition $
882createTypeEnum enum labels = UnsafeDefinition $
883 "CREATE" <+> "TYPE" <+> renderQualifiedAlias enum <+> "AS" <+> "ENUM" <+>
883 "CREATE" <+> "TYPE" <+> renderQualifiedAlias enum <+> "AS" <+> "ENUM" <+>
884 parenthesized (commaSeparated (renderLabels labels)) <> ";"
884 parenthesized (commaSeparated (renderLabels labels)) <> ";"
@@ -897,14 +897,14 @@ createTypeEnum enum labels = UnsafeDefinition $
898-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
898-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
899createTypeEnumFrom
899createTypeEnumFrom
900− :: forall hask sch enum db schema.
900+ :: forall hask sch enum schemas schema.
901 ( SOP.Generic hask
901 ( SOP.Generic hask
902 , SOP.All KnownSymbol (LabelsPG hask)
902 , SOP.All KnownSymbol (LabelsPG hask)
903 , KnownSymbol enum
903 , KnownSymbol enum
904− , Has sch db schema )
904+ , Has sch schemas schema )
905 => QualifiedAlias sch enum
905 => QualifiedAlias sch enum
906 -- ^ name of the user defined enumerated type
906 -- ^ name of the user defined enumerated type
907− -> Definition db (Alter sch (Create enum ('Typedef (PG (Enumerated hask))) schema) db)
907+ -> Definition schemas (Alter sch (Create enum ('Typedef (PG (Enumerated hask))) schema) schemas)
908createTypeEnumFrom enum = createTypeEnum enum
908createTypeEnumFrom enum = createTypeEnum enum
909 (SOP.hpure label :: NP PGlabel (LabelsPG hask))
909 (SOP.hpure label :: NP PGlabel (LabelsPG hask))
@@ -927,17 +927,17 @@ in printSQL setup
927CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
927CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
929createTypeComposite
929createTypeComposite
930− :: (KnownSymbol ty, Has sch db schema, SOP.SListI fields)
930+ :: (KnownSymbol ty, Has sch schemas schema, SOP.SListI fields)
931 => QualifiedAlias sch ty
931 => QualifiedAlias sch ty
932 -- ^ name of the user defined composite type
932 -- ^ name of the user defined composite type
933− -> NP (Aliased (TypeExpression db)) fields
933+ -> NP (Aliased (TypeExpression schemas)) fields
934 -- ^ list of attribute names and data types
934 -- ^ list of attribute names and data types
935− -> Definition db (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) db)
935+ -> Definition schemas (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) schemas)
936createTypeComposite ty fields = UnsafeDefinition $
936createTypeComposite ty fields = UnsafeDefinition $
937 "CREATE" <+> "TYPE" <+> renderQualifiedAlias ty <+> "AS" <+> parenthesized
937 "CREATE" <+> "TYPE" <+> renderQualifiedAlias ty <+> "AS" <+> parenthesized
938 (renderCommaSeparated renderField fields) <> ";"
938 (renderCommaSeparated renderField fields) <> ";"
940− renderField :: Aliased (TypeExpression db) x -> ByteString
940+ renderField :: Aliased (TypeExpression schemas) x -> ByteString
941 renderField (typ `As` alias) =
941 renderField (typ `As` alias) =
942 renderAlias alias <+> renderTypeExpression typ
942 renderAlias alias <+> renderTypeExpression typ
@@ -956,21 +956,21 @@ createTypeComposite ty fields = UnsafeDefinition $
957-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
957-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
958createTypeCompositeFrom
958createTypeCompositeFrom
959− :: forall hask sch ty db schema.
959+ :: forall hask sch ty schemas schema.
960− ( SOP.All (FieldTyped db) (RowPG hask)
960+ ( SOP.All (FieldTyped schemas) (RowPG hask)
961 , KnownSymbol ty
961 , KnownSymbol ty
962− , Has sch db schema )
962+ , Has sch schemas schema )
963 => QualifiedAlias sch ty
963 => QualifiedAlias sch ty
964 -- ^ name of the user defined composite type
964 -- ^ name of the user defined composite type
965− -> Definition db (Alter sch (Create ty ( 'Typedef (PG (Composite hask))) schema) db)
965+ -> Definition schemas (Alter sch (Create ty ( 'Typedef (PG (Composite hask))) schema) schemas)
966createTypeCompositeFrom ty = createTypeComposite ty
966createTypeCompositeFrom ty = createTypeComposite ty
967− (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped db)) fieldtype
967+ (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped schemas)) fieldtype
968− :: NP (Aliased (TypeExpression db)) (RowPG hask))
968+ :: NP (Aliased (TypeExpression schemas)) (RowPG hask))
970−class FieldTyped db ty where
970+class FieldTyped schemas ty where
971− fieldtype :: Aliased (TypeExpression db) ty
971+ fieldtype :: Aliased (TypeExpression schemas) ty
972−instance (KnownSymbol alias, PGTyped db ty)
972+instance (KnownSymbol alias, PGTyped schemas ty)
973− => FieldTyped db (alias ::: ty) where
973+ => FieldTyped schemas (alias ::: ty) where
974 fieldtype = pgtype `As` Alias
974 fieldtype = pgtype `As` Alias
976-- | Drop a type.
976-- | Drop a type.
@@ -981,54 +981,54 @@ instance (KnownSymbol alias, PGTyped db ty)
981-- >>> printSQL (dropType #schwarma :: Definition '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]] '["public" ::: '[]])
981-- >>> printSQL (dropType #schwarma :: Definition '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]] '["public" ::: '[]])
982-- DROP TYPE "schwarma";
982-- DROP TYPE "schwarma";
984− :: (Has sch db schema, Has td schema ('Typedef ty))
984+ :: (Has sch schemas schema, Has td schema ('Typedef ty))
985 => QualifiedAlias sch td
985 => QualifiedAlias sch td
986 -- ^ name of the user defined type
986 -- ^ name of the user defined type
987− -> Definition db (Alter sch (Drop td schema) db)
987+ -> Definition schemas (Alter sch (Drop td schema) schemas)
988dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderQualifiedAlias tydef <> ";"
988dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderQualifiedAlias tydef <> ";"
990-- | `ColumnTypeExpression`s are used in `createTable` commands.
990-- | `ColumnTypeExpression`s are used in `createTable` commands.
991−newtype ColumnTypeExpression (db :: DBType) (ty :: ColumnType)
991+newtype ColumnTypeExpression (schemas :: SchemasType) (ty :: ColumnType)
992 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
992 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
993 deriving (GHC.Generic,Show,Eq,Ord,NFData)
993 deriving (GHC.Generic,Show,Eq,Ord,NFData)
995-- | used in `createTable` commands as a column constraint to note that
995-- | used in `createTable` commands as a column constraint to note that
996-- @NULL@ may be present in a column
996-- @NULL@ may be present in a column
998− :: TypeExpression db (nullity ty)
998+ :: TypeExpression schemas (nullity ty)
999− -> ColumnTypeExpression db ('NoDef :=> 'Null ty)
999+ -> ColumnTypeExpression schemas ('NoDef :=> 'Null ty)
1000nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
1000nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
1002-- | used in `createTable` commands as a column constraint to ensure
1002-- | used in `createTable` commands as a column constraint to ensure
1003-- @NULL@ is not present in a column
1003-- @NULL@ is not present in a column
1004notNullable
1004notNullable
1005− :: TypeExpression db (nullity ty)
1005+ :: TypeExpression schemas (nullity ty)
1006− -> ColumnTypeExpression db ('NoDef :=> 'NotNull ty)
1006+ -> ColumnTypeExpression schemas ('NoDef :=> 'NotNull ty)
1007notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
1007notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
1009-- | used in `createTable` commands as a column constraint to give a default
1009-- | used in `createTable` commands as a column constraint to give a default
1011− :: Expression db '[] 'Ungrouped '[] ty
1011+ :: Expression ('[] :=> schemas) '[] 'Ungrouped '[] ty
1012− -> ColumnTypeExpression db ('NoDef :=> ty)
1012+ -> ColumnTypeExpression schemas ('NoDef :=> ty)
1013− -> ColumnTypeExpression db ('Def :=> ty)
1013+ -> ColumnTypeExpression schemas ('Def :=> ty)
1014default_ x ty = UnsafeColumnTypeExpression $
1014default_ x ty = UnsafeColumnTypeExpression $
1015 renderColumnTypeExpression ty <+> "DEFAULT" <+> renderExpression x
1015 renderColumnTypeExpression ty <+> "DEFAULT" <+> renderExpression x
1017-- | not a true type, but merely a notational convenience for creating
1017-- | not a true type, but merely a notational convenience for creating
1018-- unique identifier columns with type `PGint2`
1018-- unique identifier columns with type `PGint2`
1019serial2, smallserial
1019serial2, smallserial
1020− :: ColumnTypeExpression db ('Def :=> 'NotNull 'PGint2)
1020+ :: ColumnTypeExpression schemas ('Def :=> 'NotNull 'PGint2)
1021serial2 = UnsafeColumnTypeExpression "serial2"
1021serial2 = UnsafeColumnTypeExpression "serial2"
1022smallserial = UnsafeColumnTypeExpression "smallserial"
1022smallserial = UnsafeColumnTypeExpression "smallserial"
1023-- | not a true type, but merely a notational convenience for creating
1023-- | not a true type, but merely a notational convenience for creating
1024-- unique identifier columns with type `PGint4`
1024-- unique identifier columns with type `PGint4`
1025serial4, serial
1025serial4, serial
1026− :: ColumnTypeExpression db ('Def :=> 'NotNull 'PGint4)
1026+ :: ColumnTypeExpression schemas ('Def :=> 'NotNull 'PGint4)
1027serial4 = UnsafeColumnTypeExpression "serial4"
1027serial4 = UnsafeColumnTypeExpression "serial4"
1028serial = UnsafeColumnTypeExpression "serial"
1028serial = UnsafeColumnTypeExpression "serial"
1029-- | not a true type, but merely a notational convenience for creating
1029-- | not a true type, but merely a notational convenience for creating
1030-- unique identifier columns with type `PGint8`
1030-- unique identifier columns with type `PGint8`
1031serial8, bigserial
1031serial8, bigserial
1032− :: ColumnTypeExpression db ('Def :=> 'NotNull 'PGint8)
1032+ :: ColumnTypeExpression schemas ('Def :=> 'NotNull 'PGint8)
1033serial8 = UnsafeColumnTypeExpression "serial8"
1033serial8 = UnsafeColumnTypeExpression "serial8"
1034bigserial = UnsafeColumnTypeExpression "bigserial"
1034bigserial = UnsafeColumnTypeExpression "bigserial"