@@ -154,7 +154,7 @@ createTable
154 => QualifiedAlias sch tab -- ^ the name of the table to add
154 => QualifiedAlias sch tab -- ^ the name of the table to add
155 -> NP (Aliased (ColumnTypeExpression db0)) columns
155 -> NP (Aliased (ColumnTypeExpression db0)) columns
156 -- ^ the names and datatype of each column
156 -- ^ the names and datatype of each column
157− -> NP (Aliased (TableConstraintExpression db1 table)) constraints
157+ -> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
158 -- ^ constraints that must hold for the table
158 -- ^ constraints that must hold for the table
159 -> Definition db0 db1
159 -> Definition db0 db1
160createTable tab columns constraints = UnsafeDefinition $
160createTable tab columns constraints = UnsafeDefinition $
@@ -190,7 +190,7 @@ createTableIfNotExists
190 => QualifiedAlias sch tab -- ^ the name of the table to add
190 => QualifiedAlias sch tab -- ^ the name of the table to add
191 -> NP (Aliased (ColumnTypeExpression db)) columns
191 -> NP (Aliased (ColumnTypeExpression db)) columns
192 -- ^ the names and datatype of each column
192 -- ^ the names and datatype of each column
193− -> NP (Aliased (TableConstraintExpression db table)) constraints
193+ -> NP (Aliased (TableConstraintExpression sch tab db)) constraints
194 -- ^ constraints that must hold for the table
194 -- ^ constraints that must hold for the table
195 -> Definition db db
195 -> Definition db db
196createTableIfNotExists tab columns constraints = UnsafeDefinition $
196createTableIfNotExists tab columns constraints = UnsafeDefinition $
@@ -204,9 +204,9 @@ renderCreation
204 , SOP.SListI columns
204 , SOP.SListI columns
205 , SOP.SListI constraints )
205 , SOP.SListI constraints )
206 => QualifiedAlias sch tab -- ^ the name of the table to add
206 => QualifiedAlias sch tab -- ^ the name of the table to add
207− -> NP (Aliased (ColumnTypeExpression schema0)) columns
207+ -> NP (Aliased (ColumnTypeExpression db0)) columns
208 -- ^ the names and datatype of each column
208 -- ^ the names and datatype of each column
209− -> NP (Aliased (TableConstraintExpression schema1 table)) constraints
209+ -> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
210 -- ^ constraints that must hold for the table
210 -- ^ constraints that must hold for the table
211 -> ByteString
211 -> ByteString
212renderCreation tab columns constraints = renderQualifiedAlias tab
212renderCreation tab columns constraints = renderQualifiedAlias tab
@@ -222,7 +222,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
222 renderColumnDef (ty `As` column) =
222 renderColumnDef (ty `As` column) =
223 renderAlias column <+> renderColumnTypeExpression ty
223 renderAlias column <+> renderColumnTypeExpression ty
224 renderConstraint
224 renderConstraint
225− :: Aliased (TableConstraintExpression schema columns) constraint
225+ :: Aliased (TableConstraintExpression sch tab db) constraint
226 -> ByteString
226 -> ByteString
227 renderConstraint (constraint `As` alias) =
227 renderConstraint (constraint `As` alias) =
228 "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
228 "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
@@ -240,9 +240,10 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
240-- violate a constraint, an error is raised. This applies
240-- violate a constraint, an error is raised. This applies
241-- even if the value came from the default value definition.
241-- even if the value came from the default value definition.
242newtype TableConstraintExpression
242newtype TableConstraintExpression
243 (db :: DBType)
245 (db :: DBType)
245− (tableConstraint :: TableConstraint)
246+ (constraint :: TableConstraint)
246 = UnsafeTableConstraintExpression
247 = UnsafeTableConstraintExpression
247 { renderTableConstraintExpression :: ByteString }
248 { renderTableConstraintExpression :: ByteString }
248 deriving (GHC.Generic,Show,Eq,Ord,NFData)
249 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -278,7 +279,7 @@ check
278 -- ^ specify the subcolumns which are getting checked
279 -- ^ specify the subcolumns which are getting checked
279 -> (forall t. Condition db '[t ::: subcolumns] 'Ungrouped '[])
280 -> (forall t. Condition db '[t ::: subcolumns] 'Ungrouped '[])
280 -- ^ a closed `Condition` on those subcolumns
281 -- ^ a closed `Condition` on those subcolumns
281− -> TableConstraintExpression db tab ('Check aliases)
282+ -> TableConstraintExpression sch tab db ('Check aliases)
282check _cols condition = UnsafeTableConstraintExpression $
283check _cols condition = UnsafeTableConstraintExpression $
283 "CHECK" <+> parenthesized (renderExpression condition)
284 "CHECK" <+> parenthesized (renderExpression condition)
@@ -306,11 +307,11 @@ let
306CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
307CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
309− :: ( Has alias schema ('Table table)
310+ :: ( HasQualified sch tab db schema('Table table)
310 , HasAll aliases (TableToRow table) subcolumns )
311 , HasAll aliases (TableToRow table) subcolumns )
311 => NP Alias aliases
312 => NP Alias aliases
312 -- ^ specify subcolumns which together are unique for each row
313 -- ^ specify subcolumns which together are unique for each row
313− -> TableConstraintExpression db alias ('Unique aliases)
314+ -> TableConstraintExpression sch tab db ('Unique aliases)
314unique columns = UnsafeTableConstraintExpression $
315unique columns = UnsafeTableConstraintExpression $
315 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
316 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
@@ -339,12 +340,12 @@ let
339CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
340CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
341primaryKey
342primaryKey
342− :: ( Has alias schema ('Table table)
343+ :: ( HasQualified sch tab db schema ('Table table)
343 , HasAll aliases (TableToColumns table) subcolumns
344 , HasAll aliases (TableToColumns table) subcolumns
344 , AllNotNull subcolumns )
345 , AllNotNull subcolumns )
345 => NP Alias aliases
346 => NP Alias aliases
346 -- ^ specify the subcolumns which together form a primary key.
347 -- ^ specify the subcolumns which together form a primary key.
347− -> TableConstraintExpression db alias ('PrimaryKey aliases)
348+ -> TableConstraintExpression sch tab db ('PrimaryKey aliases)
348primaryKey columns = UnsafeTableConstraintExpression $
349primaryKey columns = UnsafeTableConstraintExpression $
349 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
350 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
@@ -422,7 +423,7 @@ in printSQL setup
422CREATE 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);
423CREATE 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);
424foreignKey
425foreignKey
425− :: (ForeignKeyed schema child parent
426+ :: (ForeignKeyed db sch schema child parent
426 table reftable
427 table reftable
427 columns refcolumns
428 columns refcolumns
428 constraints cols
429 constraints cols
@@ -437,7 +438,7 @@ foreignKey
437 -- ^ what to do when reference is deleted
438 -- ^ what to do when reference is deleted
438 -> OnUpdateClause
439 -> OnUpdateClause
439 -- ^ what to do when reference is updated
440 -- ^ what to do when reference is updated
440− -> TableConstraintExpression db child
441+ -> TableConstraintExpression sch child db
441 ('ForeignKey columns parent refcolumns)
442 ('ForeignKey columns parent refcolumns)
442foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
443foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
443 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
444 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
@@ -447,14 +448,16 @@ foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
447 <+> renderOnUpdateClause onupd
448 <+> renderOnUpdateClause onupd
449-- | A constraint synonym between types involved in a foreign key constraint.
450-- | A constraint synonym between types involved in a foreign key constraint.
450−type ForeignKeyed schema
451+type ForeignKeyed db
451 child parent
454 child parent
452 table reftable
455 table reftable
453 columns refcolumns
456 columns refcolumns
454 constraints cols
457 constraints cols
455 reftys tys =
458 reftys tys =
456− ( Has child schema ('Table table)
459+ ( HasQualified sch child db schema ('Table table)
457− , Has parent schema ('Table reftable)
460+ , HasQualified sch parent db schema ('Table reftable)
458 , HasAll columns (TableToColumns table) tys
461 , HasAll columns (TableToColumns table) tys
459 , reftable ~ (constraints :=> cols)
462 , reftable ~ (constraints :=> cols)
460 , HasAll refcolumns cols reftys
463 , HasAll refcolumns cols reftys
@@ -571,11 +574,11 @@ newtype AlterTable
571-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
574-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
572addConstraint
575addConstraint
573 :: ( KnownSymbol alias
576 :: ( KnownSymbol alias
574− , Has tab schema ('Table table0)
577+ , HasQualified sch tab db schema ('Table table0)
575 , table0 ~ (constraints :=> columns)
578 , table0 ~ (constraints :=> columns)
576 , table1 ~ (Create alias constraint constraints :=> columns) )
579 , table1 ~ (Create alias constraint constraints :=> columns) )
577 => Alias alias
580 => Alias alias
578− -> TableConstraintExpression db tab constraint
581+ -> TableConstraintExpression sch tab db constraint
579 -- ^ constraint to add
582 -- ^ constraint to add
580 -> AlterTable tab table1 db
583 -> AlterTable tab table1 db
581addConstraint alias constraint = UnsafeAlterTable $
584addConstraint alias constraint = UnsafeAlterTable $