@@ -110,7 +110,7 @@ CREATE statements
110-- renderDefinition $
110-- renderDefinition $
111-- createTable #tab (int `As` #a :* real `As` #b :* Nil) Nil
111-- createTable #tab (int `As` #a :* real `As` #b :* Nil) Nil
113−-- "CREATE TABLE tab (a int, b real);"
113+-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" real);"
114createTable
114createTable
115 :: ( KnownSymbol table
115 :: ( KnownSymbol table
116 , columns ~ (col ': cols)
116 , columns ~ (col ': cols)
@@ -136,7 +136,7 @@ createTable table columns constraints = UnsafeDefinition $
136-- renderDefinition
136-- renderDefinition
137-- (createTableIfNotExists #tab (int `As` #a :* real `As` #b :* Nil) Nil :: Definition Schema Schema)
137-- (createTableIfNotExists #tab (int `As` #a :* real `As` #b :* Nil) Nil :: Definition Schema Schema)
139−-- "CREATE TABLE IF NOT EXISTS tab (a int, b real);"
139+-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
140createTableIfNotExists
140createTableIfNotExists
141 :: ( Has table schema (constraints :=> columns)
141 :: ( Has table schema (constraints :=> columns)
142 , SOP.SListI columns
142 , SOP.SListI columns
@@ -225,7 +225,7 @@ renderColumn (Column column) = renderAlias column
225-- (int & notNull) `As` #b :* Nil )
225-- (int & notNull) `As` #b :* Nil )
226-- ( check (Column #a :* Column #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
226-- ( check (Column #a :* Column #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
228−-- "CREATE TABLE tab (a int NOT NULL, b int NOT NULL, CONSTRAINT inequality CHECK ((a > b)));"
228+-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
230 :: NP (Column columns) subcolumns
230 :: NP (Column columns) subcolumns
231 -> Condition '[table ::: ColumnsToRelation subcolumns] 'Ungrouped '[]
231 -> Condition '[table ::: ColumnsToRelation subcolumns] 'Ungrouped '[]
@@ -244,7 +244,7 @@ check _cols condition = UnsafeTableConstraintExpression $
244-- int `As` #b :* Nil )
244-- int `As` #b :* Nil )
245-- ( unique (Column #a :* Column #b :* Nil) `As` #uq_a_b :* Nil )
245-- ( unique (Column #a :* Column #b :* Nil) `As` #uq_a_b :* Nil )
247−-- "CREATE TABLE tab (a int, b int, CONSTRAINT uq_a_b UNIQUE (a, b));"
247+-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
249 :: SOP.SListI subcolumns
249 :: SOP.SListI subcolumns
250 => NP (Column columns) subcolumns
250 => NP (Column columns) subcolumns
@@ -264,7 +264,7 @@ unique columns = UnsafeTableConstraintExpression $
264-- (text & notNull) `As` #name :* Nil )
264-- (text & notNull) `As` #name :* Nil )
265-- ( primaryKey (Column #id :* Nil) `As` #pk_id :* Nil )
265-- ( primaryKey (Column #id :* Nil) `As` #pk_id :* Nil )
267−-- "CREATE TABLE tab (id serial, name text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id));"
267+-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
268primaryKey
268primaryKey
269 :: (SOP.SListI subcolumns, AllNotNull subcolumns)
269 :: (SOP.SListI subcolumns, AllNotNull subcolumns)
270 => NP (Column columns) subcolumns
270 => NP (Column columns) subcolumns
@@ -313,7 +313,7 @@ primaryKey columns = UnsafeTableConstraintExpression $
313-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
313-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
314-- in renderDefinition setup
314-- in renderDefinition setup
316−-- "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);"
316+-- "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);"
317foreignKey
317foreignKey
318 :: ForeignKeyed schema table reftable subcolumns refsubcolumns
318 :: ForeignKeyed schema table reftable subcolumns refsubcolumns
319 => NP (Column columns) subcolumns
319 => NP (Column columns) subcolumns
@@ -390,7 +390,7 @@ DROP statements
390-- | `dropTable` removes a table from the schema.
390-- | `dropTable` removes a table from the schema.
392-- >>> renderDefinition $ dropTable #muh_table
392-- >>> renderDefinition $ dropTable #muh_table
393−-- "DROP TABLE muh_table;"
393+-- "DROP TABLE \"muh_table\";"
395 :: KnownSymbol table
395 :: KnownSymbol table
396 => Alias table -- ^ table to remove
396 => Alias table -- ^ table to remove
@@ -416,7 +416,7 @@ alterTable table alteration = UnsafeDefinition $
416-- | `alterTableRename` changes the name of a table from the schema.
416-- | `alterTableRename` changes the name of a table from the schema.
418-- >>> renderDefinition $ alterTableRename #foo #bar
418-- >>> renderDefinition $ alterTableRename #foo #bar
419−-- "ALTER TABLE foo RENAME TO bar;"
419+-- "ALTER TABLE \"foo\" RENAME TO \"bar\";"
420alterTableRename
420alterTableRename
421 :: (KnownSymbol table0, KnownSymbol table1)
421 :: (KnownSymbol table0, KnownSymbol table1)
422 => Alias table0 -- ^ table to rename
422 => Alias table0 -- ^ table to rename
@@ -445,7 +445,7 @@ newtype AlterTable
445-- definition = alterTable #tab (addConstraint #positive (check (Column #col :* Nil) (#col .> 0)))
445-- definition = alterTable #tab (addConstraint #positive (check (Column #col :* Nil) (#col .> 0)))
446-- in renderDefinition definition
446-- in renderDefinition definition
448−-- "ALTER TABLE tab ADD CONSTRAINT positive CHECK ((col > 0));"
448+-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
449addConstraint
449addConstraint
450 :: KnownSymbol alias
450 :: KnownSymbol alias
451 => Alias alias
451 => Alias alias
@@ -467,7 +467,7 @@ addConstraint alias constraint = UnsafeAlterTable $
467-- definition = alterTable #tab (dropConstraint #positive)
467-- definition = alterTable #tab (dropConstraint #positive)
468-- in renderDefinition definition
468-- in renderDefinition definition
470−-- "ALTER TABLE tab DROP CONSTRAINT positive;"
470+-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
471dropConstraint
471dropConstraint
472 :: KnownSymbol constraint
472 :: KnownSymbol constraint
473 => Alias constraint
473 => Alias constraint
@@ -493,7 +493,7 @@ class AddColumn ty where
493 -- definition = alterTable #tab (addColumn #col2 (text & default_ "foo"))
493 -- definition = alterTable #tab (addColumn #col2 (text & default_ "foo"))
494 -- in renderDefinition definition
494 -- in renderDefinition definition
496− -- "ALTER TABLE tab ADD COLUMN col2 text DEFAULT E'foo';"
496+ -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text DEFAULT E'foo';"
498 -- >>> :{
498 -- >>> :{
@@ -505,7 +505,7 @@ class AddColumn ty where
505 -- definition = alterTable #tab (addColumn #col2 text)
505 -- definition = alterTable #tab (addColumn #col2 text)
506 -- in renderDefinition definition
506 -- in renderDefinition definition
508− -- "ALTER TABLE tab ADD COLUMN col2 text;"
508+ -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
509 addColumn
509 addColumn
510 :: KnownSymbol column
510 :: KnownSymbol column
511 => Alias column -- ^ column to add
511 => Alias column -- ^ column to add
@@ -532,7 +532,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
532-- definition = alterTable #tab (dropColumn #col2)
532-- definition = alterTable #tab (dropColumn #col2)
533-- in renderDefinition definition
533-- in renderDefinition definition
535−-- "ALTER TABLE tab DROP COLUMN col2;"
535+-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
536dropColumn
536dropColumn
537 :: KnownSymbol column
537 :: KnownSymbol column
538 => Alias column -- ^ column to remove
538 => Alias column -- ^ column to remove
@@ -552,7 +552,7 @@ dropColumn column = UnsafeAlterTable $
552-- definition = alterTable #tab (renameColumn #foo #bar)
552-- definition = alterTable #tab (renameColumn #foo #bar)
553-- in renderDefinition definition
553-- in renderDefinition definition
555−-- "ALTER TABLE tab RENAME COLUMN foo TO bar;"
555+-- "ALTER TABLE \"tab\" RENAME COLUMN \"foo\" TO \"bar\";"
556renameColumn
556renameColumn
557 :: (KnownSymbol column0, KnownSymbol column1)
557 :: (KnownSymbol column0, KnownSymbol column1)
558 => Alias column0 -- ^ column to rename
558 => Alias column0 -- ^ column to rename
@@ -589,7 +589,7 @@ newtype AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
589-- definition = alterTable #tab (alterColumn #col (setDefault 5))
589-- definition = alterTable #tab (alterColumn #col (setDefault 5))
590-- in renderDefinition definition
590-- in renderDefinition definition
592−-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
592+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
593setDefault
593setDefault
594 :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
594 :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
595 -> AlterColumn (constraint :=> ty) ('Def :=> ty)
595 -> AlterColumn (constraint :=> ty) ('Def :=> ty)
@@ -606,7 +606,7 @@ setDefault expression = UnsafeAlterColumn $
606-- definition = alterTable #tab (alterColumn #col dropDefault)
606-- definition = alterTable #tab (alterColumn #col dropDefault)
607-- in renderDefinition definition
607-- in renderDefinition definition
609−-- "ALTER TABLE tab ALTER COLUMN col DROP DEFAULT;"
609+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP DEFAULT;"
610dropDefault :: AlterColumn ('Def :=> ty) ('NoDef :=> ty)
610dropDefault :: AlterColumn ('Def :=> ty) ('NoDef :=> ty)
611dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
611dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
@@ -622,7 +622,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
622-- definition = alterTable #tab (alterColumn #col setNotNull)
622-- definition = alterTable #tab (alterColumn #col setNotNull)
623-- in renderDefinition definition
623-- in renderDefinition definition
625−-- "ALTER TABLE tab ALTER COLUMN col SET NOT NULL;"
625+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET NOT NULL;"
626setNotNull
626setNotNull
627 :: AlterColumn (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
627 :: AlterColumn (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
628setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
628setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
@@ -637,7 +637,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
637-- definition = alterTable #tab (alterColumn #col dropNotNull)
637-- definition = alterTable #tab (alterColumn #col dropNotNull)
638-- in renderDefinition definition
638-- in renderDefinition definition
640−-- "ALTER TABLE tab ALTER COLUMN col DROP NOT NULL;"
640+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP NOT NULL;"
641dropNotNull
641dropNotNull
642 :: AlterColumn (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
642 :: AlterColumn (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
643dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
643dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
@@ -655,6 +655,6 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
655-- alterTable #tab (alterColumn #col (alterType (numeric & notNull)))
655-- alterTable #tab (alterColumn #col (alterType (numeric & notNull)))
656-- in renderDefinition definition
656-- in renderDefinition definition
658−-- "ALTER TABLE tab ALTER COLUMN col TYPE numeric NOT NULL;"
658+-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" TYPE numeric NOT NULL;"
659alterType :: TypeExpression ty -> AlterColumn ty0 ty
659alterType :: TypeExpression ty -> AlterColumn ty0 ty
660alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderTypeExpression ty
660alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderTypeExpression ty