@@ -334,6 +334,37 @@ primaryKey columns = UnsafeTableConstraintExpression $
334-- in renderDefinition setup
334-- in renderDefinition setup
336-- "CREATE TABLE \"users\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_users\" PRIMARY KEY (\"id\")); CREATE TABLE \"emails\" (\"id\" serial, \"user_id\" int NOT NULL, \"email\" text, CONSTRAINT \"pk_emails\" PRIMARY KEY (\"id\"), CONSTRAINT \"fk_user_id\" FOREIGN KEY (\"user_id\") REFERENCES \"users\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE);"
336-- "CREATE TABLE \"users\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_users\" PRIMARY KEY (\"id\")); CREATE TABLE \"emails\" (\"id\" serial, \"user_id\" int NOT NULL, \"email\" text, CONSTRAINT \"pk_emails\" PRIMARY KEY (\"id\"), CONSTRAINT \"fk_user_id\" FOREIGN KEY (\"user_id\") REFERENCES \"users\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE);"
338+-- A `foreignKey` can even be a table self-reference.
342+-- '[ "employees" :::
343+-- '[ "employees_pk" ::: 'PrimaryKey '["id"]
344+-- , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"]
346+-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
347+-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
348+-- , "employer_id" ::: 'NoDef :=> 'Null 'PGint4
355+-- setup :: Definition '[] Schema
357+-- createTable #employees
358+-- ( serial `As` #id :*
359+-- (text & notNull) `As` #name :*
360+-- integer `As` #employer_id :* Nil )
361+-- ( primaryKey #id `As` #employees_pk :*
362+-- foreignKey #employer_id #employees #id
363+-- OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
364+-- in renderDefinition setup
366+-- "CREATE TABLE \"employees\" (\"id\" serial, \"name\" text NOT NULL, \"employer_id\" integer, CONSTRAINT \"employees_pk\" PRIMARY KEY (\"id\"), CONSTRAINT \"employees_employer_fk\" FOREIGN KEY (\"employer_id\") REFERENCES \"employees\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE);"
337foreignKey
368foreignKey
338 :: ( Has child schema table
369 :: ( Has child schema table
339 , Has parent schema reftable
370 , Has parent schema reftable