on dev help sign in
it compiles!
commit1cad1b773a208baf56528f28613fe36f6de948fb authorEitan Chatav <eitan.chatav@gmail.com> dateFri 23 Nov 2018, 20:45 (8 years ago) parent7a8646c
1 file changed+22−19
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+22−19
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+22−19
@@ -154,7 +154,7 @@ createTable
154154 => QualifiedAlias sch tab -- ^ the name of the table to add
155155 -> NP (Aliased (ColumnTypeExpression db0)) columns
156156 -- ^ the names and datatype of each column
157− -> NP (Aliased (TableConstraintExpression db1 table)) constraints
157+ -> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
158158 -- ^ constraints that must hold for the table
159159 -> Definition db0 db1
160160createTable tab columns constraints = UnsafeDefinition $
@@ -190,7 +190,7 @@ createTableIfNotExists
190190 => QualifiedAlias sch tab -- ^ the name of the table to add
191191 -> NP (Aliased (ColumnTypeExpression db)) columns
192192 -- ^ the names and datatype of each column
193− -> NP (Aliased (TableConstraintExpression db table)) constraints
193+ -> NP (Aliased (TableConstraintExpression sch tab db)) constraints
194194 -- ^ constraints that must hold for the table
195195 -> Definition db db
196196createTableIfNotExists tab columns constraints = UnsafeDefinition $
@@ -204,9 +204,9 @@ renderCreation
204204 , SOP.SListI columns
205205 , SOP.SListI constraints )
206206 => QualifiedAlias sch tab -- ^ the name of the table to add
207− -> NP (Aliased (ColumnTypeExpression schema0)) columns
207+ -> NP (Aliased (ColumnTypeExpression db0)) columns
208208 -- ^ the names and datatype of each column
209− -> NP (Aliased (TableConstraintExpression schema1 table)) constraints
209+ -> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
210210 -- ^ constraints that must hold for the table
211211 -> ByteString
212212renderCreation tab columns constraints = renderQualifiedAlias tab
@@ -222,7 +222,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
222222 renderColumnDef (ty `As` column) =
223223 renderAlias column <+> renderColumnTypeExpression ty
224224 renderConstraint
225− :: Aliased (TableConstraintExpression schema columns) constraint
225+ :: Aliased (TableConstraintExpression sch tab db) constraint
226226 -> ByteString
227227 renderConstraint (constraint `As` alias) =
228228 "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
@@ -240,9 +240,10 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
240240-- violate a constraint, an error is raised. This applies
241241-- even if the value came from the default value definition.
242242newtype TableConstraintExpression
243+ (sch :: Symbol)
244+ (tab :: Symbol)
243245 (db :: DBType)
244− (table :: Symbol)
245− (tableConstraint :: TableConstraint)
246+ (constraint :: TableConstraint)
246247 = UnsafeTableConstraintExpression
247248 { renderTableConstraintExpression :: ByteString }
248249 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -278,7 +279,7 @@ check
278279 -- ^ specify the subcolumns which are getting checked
279280 -> (forall t. Condition db '[t ::: subcolumns] 'Ungrouped '[])
280281 -- ^ a closed `Condition` on those subcolumns
281− -> TableConstraintExpression db tab ('Check aliases)
282+ -> TableConstraintExpression sch tab db ('Check aliases)
282283check _cols condition = UnsafeTableConstraintExpression $
283284 "CHECK" <+> parenthesized (renderExpression condition)
284285
@@ -306,11 +307,11 @@ let
306307CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
307308-}
308309unique
309− :: ( Has alias schema ('Table table)
310+ :: ( HasQualified sch tab db schema('Table table)
310311 , HasAll aliases (TableToRow table) subcolumns )
311312 => NP Alias aliases
312313 -- ^ specify subcolumns which together are unique for each row
313− -> TableConstraintExpression db alias ('Unique aliases)
314+ -> TableConstraintExpression sch tab db ('Unique aliases)
314315unique columns = UnsafeTableConstraintExpression $
315316 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
316317
@@ -339,12 +340,12 @@ let
339340CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
340341-}
341342primaryKey
342− :: ( Has alias schema ('Table table)
343+ :: ( HasQualified sch tab db schema ('Table table)
343344 , HasAll aliases (TableToColumns table) subcolumns
344345 , AllNotNull subcolumns )
345346 => NP Alias aliases
346347 -- ^ specify the subcolumns which together form a primary key.
347− -> TableConstraintExpression db alias ('PrimaryKey aliases)
348+ -> TableConstraintExpression sch tab db ('PrimaryKey aliases)
348349primaryKey columns = UnsafeTableConstraintExpression $
349350 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
350351
@@ -422,7 +423,7 @@ in printSQL setup
422423CREATE 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);
423424-}
424425foreignKey
425− :: (ForeignKeyed schema child parent
426+ :: (ForeignKeyed db sch schema child parent
426427 table reftable
427428 columns refcolumns
428429 constraints cols
@@ -437,7 +438,7 @@ foreignKey
437438 -- ^ what to do when reference is deleted
438439 -> OnUpdateClause
439440 -- ^ what to do when reference is updated
440− -> TableConstraintExpression db child
441+ -> TableConstraintExpression sch child db
441442 ('ForeignKey columns parent refcolumns)
442443foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
443444 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
@@ -447,14 +448,16 @@ foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
447448 <+> renderOnUpdateClause onupd
448449
449450-- | A constraint synonym between types involved in a foreign key constraint.
450−type ForeignKeyed schema
451+type ForeignKeyed db
452+ sch
453+ schema
451454 child parent
452455 table reftable
453456 columns refcolumns
454457 constraints cols
455458 reftys tys =
456− ( Has child schema ('Table table)
457− , Has parent schema ('Table reftable)
459+ ( HasQualified sch child db schema ('Table table)
460+ , HasQualified sch parent db schema ('Table reftable)
458461 , HasAll columns (TableToColumns table) tys
459462 , reftable ~ (constraints :=> cols)
460463 , HasAll refcolumns cols reftys
@@ -571,11 +574,11 @@ newtype AlterTable
571574-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
572575addConstraint
573576 :: ( KnownSymbol alias
574− , Has tab schema ('Table table0)
577+ , HasQualified sch tab db schema ('Table table0)
575578 , table0 ~ (constraints :=> columns)
576579 , table1 ~ (Create alias constraint constraints :=> columns) )
577580 => Alias alias
578− -> TableConstraintExpression db tab constraint
581+ -> TableConstraintExpression sch tab db constraint
579582 -- ^ constraint to add
580583 -> AlterTable tab table1 db
581584addConstraint alias constraint = UnsafeAlterTable $