@@ -116,20 +116,21 @@ newtype Definition
116instance Category Definition where
116instance Category Definition where
117 id = UnsafeDefinition ";"
117 id = UnsafeDefinition ";"
118 ddl1 . ddl0 = UnsafeDefinition $
118 ddl1 . ddl0 = UnsafeDefinition $
119− renderDefinition ddl0 <+> renderDefinition ddl1
119+ renderDefinition ddl0 <> "\n" <> renderDefinition ddl1
121{-----------------------------------------
121{-----------------------------------------
122CREATE statements
122CREATE statements
123-----------------------------------------}
123-----------------------------------------}
125−-- | `createTable` adds a table to the schema.
125+{- | `createTable` adds a table to the schema.
127−-- >>> :set -XOverloadedLabels
127+>>> :set -XOverloadedLabels
129−-- renderDefinition $
129+Data.ByteString.Char8.putStrLn . renderDefinition $
130−-- createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
130+ createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
132−-- "CREATE TABLE \"tab\" (\"a\" int NULL, \"b\" real NULL);"
132+CREATE TABLE "tab" ("a" int NULL, "b" real NULL);
133createTable
134createTable
134 :: ( KnownSymbol table
135 :: ( KnownSymbol table
135 , columns ~ (col ': cols)
136 , columns ~ (col ': cols)
@@ -145,18 +146,19 @@ createTable
145createTable tab columns constraints = UnsafeDefinition $
146createTable tab columns constraints = UnsafeDefinition $
146 "CREATE TABLE" <+> renderCreation tab columns constraints
147 "CREATE TABLE" <+> renderCreation tab columns constraints
148−-- | `createTableIfNotExists` creates a table if it doesn't exist, but does not add it to the schema.
149+{-| `createTableIfNotExists` creates a table if it doesn't exist, but does not add it to the schema.
149−-- Instead, the schema already has the table so if the table did not yet exist, the schema was wrong.
150+Instead, the schema already has the table so if the table did not yet exist, the schema was wrong.
150−-- `createTableIfNotExists` fixes this. Interestingly, this property makes it an idempotent in the `Category` `Definition`.
151+`createTableIfNotExists` fixes this. Interestingly, this property makes it an idempotent in the `Category` `Definition`.
152−-- >>> :set -XOverloadedLabels -XTypeApplications
153+>>> :set -XOverloadedLabels -XTypeApplications
153−-- >>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
154+>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
154−-- >>> type Schema = '["tab" ::: 'Table Table]
155+>>> type Schema = '["tab" ::: 'Table Table]
156−-- renderDefinition
157+Data.ByteString.Char8.putStrLn $ renderDefinition
157−-- (createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil :: Definition Schema Schema)
158+ (createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil :: Definition Schema Schema)
159−-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int NULL, \"b\" real NULL);"
160+CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
160createTableIfNotExists
162createTableIfNotExists
161 :: ( Has table schema ('Table (constraints :=> columns))
163 :: ( Has table schema ('Table (constraints :=> columns))
162 , SOP.SListI columns
164 , SOP.SListI columns
@@ -220,29 +222,30 @@ newtype TableConstraintExpression
220 { renderTableConstraintExpression :: ByteString }
222 { renderTableConstraintExpression :: ByteString }
221 deriving (GHC.Generic,Show,Eq,Ord,NFData)
223 deriving (GHC.Generic,Show,Eq,Ord,NFData)
223−-- | A `check` constraint is the most generic `TableConstraint` type.
225+{-| A `check` constraint is the most generic `TableConstraint` type.
224−-- It allows you to specify that the value in a certain column must satisfy
226+It allows you to specify that the value in a certain column must satisfy
225−-- a Boolean (truth-value) expression.
227+a Boolean (truth-value) expression.
228−-- type Schema = '[
230+type Schema = '[
229−-- "tab" ::: 'Table ('[ "inequality" ::: 'Check '["a","b"]] :=> '[
231+ "tab" ::: 'Table ('[ "inequality" ::: 'Check '["a","b"]] :=> '[
230−-- "a" ::: 'NoDef :=> 'NotNull 'PGint4,
232+ "a" ::: 'NoDef :=> 'NotNull 'PGint4,
231−-- "b" ::: 'NoDef :=> 'NotNull 'PGint4
233+ "b" ::: 'NoDef :=> 'NotNull 'PGint4
237−-- definition :: Definition '[] Schema
239+ definition :: Definition '[] Schema
238−-- definition = createTable #tab
240+ definition = createTable #tab
239−-- ( (int & notNullable) `As` #a :*
241+ ( (int & notNullable) `As` #a :*
240−-- (int & notNullable) `As` #b :* Nil )
242+ (int & notNullable) `As` #b :* Nil )
241−-- ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
243+ ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
244−-- >>> renderDefinition definition
246+>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
245−-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
247+CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
247 :: ( Has alias schema ('Table table)
250 :: ( Has alias schema ('Table table)
248 , HasAll aliases (TableToRelation table) subcolumns )
251 , HasAll aliases (TableToRelation table) subcolumns )
@@ -254,28 +257,29 @@ check
254check _cols condition = UnsafeTableConstraintExpression $
257check _cols condition = UnsafeTableConstraintExpression $
255 "CHECK" <+> parenthesized (renderExpression condition)
258 "CHECK" <+> parenthesized (renderExpression condition)
257−-- | A `unique` constraint ensure that the data contained in a column,
260+{-| A `unique` constraint ensure that the data contained in a column,
258−-- or a group of columns, is unique among all the rows in the table.
261+or a group of columns, is unique among all the rows in the table.
261−-- type Schema = '[
264+type Schema = '[
262−-- "tab" ::: 'Table( '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[
265+ "tab" ::: 'Table( '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[
263−-- "a" ::: 'NoDef :=> 'Null 'PGint4,
266+ "a" ::: 'NoDef :=> 'Null 'PGint4,
264−-- "b" ::: 'NoDef :=> 'Null 'PGint4
267+ "b" ::: 'NoDef :=> 'Null 'PGint4
270−-- definition :: Definition '[] Schema
273+ definition :: Definition '[] Schema
271−-- definition = createTable #tab
274+ definition = createTable #tab
272−-- ( (int & nullable) `As` #a :*
275+ ( (int & nullable) `As` #a :*
273−-- (int & nullable) `As` #b :* Nil )
276+ (int & nullable) `As` #b :* Nil )
274−-- ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
277+ ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
277−-- >>> renderDefinition definition
280+>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
278−-- "CREATE TABLE \"tab\" (\"a\" int NULL, \"b\" int NULL, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
281+CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
280 :: ( Has alias schema ('Table table)
284 :: ( Has alias schema ('Table table)
281 , HasAll aliases (TableToRelation table) subcolumns )
285 , HasAll aliases (TableToRelation table) subcolumns )
@@ -285,29 +289,30 @@ unique
285unique columns = UnsafeTableConstraintExpression $
289unique columns = UnsafeTableConstraintExpression $
286 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
290 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
288−-- | A `primaryKey` constraint indicates that a column, or group of columns,
292+{-| A `primaryKey` constraint indicates that a column, or group of columns,
289−-- can be used as a unique identifier for rows in the table.
293+can be used as a unique identifier for rows in the table.
290−-- This requires that the values be both unique and not null.
294+This requires that the values be both unique and not null.
293−-- type Schema = '[
297+type Schema = '[
294−-- "tab" ::: 'Table ('[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[
298+ "tab" ::: 'Table ('[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[
295−-- "id" ::: 'Def :=> 'NotNull 'PGint4,
299+ "id" ::: 'Def :=> 'NotNull 'PGint4,
296−-- "name" ::: 'NoDef :=> 'NotNull 'PGtext
300+ "name" ::: 'NoDef :=> 'NotNull 'PGtext
302−-- definition :: Definition '[] Schema
306+ definition :: Definition '[] Schema
303−-- definition = createTable #tab
307+ definition = createTable #tab
304−-- ( serial `As` #id :*
308+ ( serial `As` #id :*
305−-- (text & notNullable) `As` #name :* Nil )
309+ (text & notNullable) `As` #name :* Nil )
306−-- ( primaryKey #id `As` #pk_id :* Nil )
310+ ( primaryKey #id `As` #pk_id :* Nil )
309−-- >>> renderDefinition definition
313+>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
310−-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
314+CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
311primaryKey
316primaryKey
312 :: ( Has alias schema ('Table table)
317 :: ( Has alias schema ('Table table)
313 , HasAll aliases (TableToColumns table) subcolumns
318 , HasAll aliases (TableToColumns table) subcolumns
@@ -318,78 +323,79 @@ primaryKey
318primaryKey columns = UnsafeTableConstraintExpression $
323primaryKey columns = UnsafeTableConstraintExpression $
319 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
324 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
321−-- | A `foreignKey` specifies that the values in a column
326+{-| A `foreignKey` specifies that the values in a column
322−-- (or a group of columns) must match the values appearing in some row of
327+(or a group of columns) must match the values appearing in some row of
323−-- another table. We say this maintains the referential integrity
328+another table. We say this maintains the referential integrity
324−-- between two related tables.
329+between two related tables.
327−-- type Schema =
332+type Schema =
328−-- '[ "users" ::: 'Table (
333+ '[ "users" ::: 'Table (
329−-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
334+ '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
330−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
335+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
331−-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
336+ , "name" ::: 'NoDef :=> 'NotNull 'PGtext
333−-- , "emails" ::: 'Table (
338+ , "emails" ::: 'Table (
334−-- '[ "pk_emails" ::: 'PrimaryKey '["id"]
339+ '[ "pk_emails" ::: 'PrimaryKey '["id"]
335−-- , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
340+ , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
337−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
342+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
338−-- , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
343+ , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
339−-- , "email" ::: 'NoDef :=> 'Null 'PGtext
344+ , "email" ::: 'NoDef :=> 'Null 'PGtext
346−-- setup :: Definition '[] Schema
351+ setup :: Definition '[] Schema
347−-- setup =
352+ setup =
348−-- createTable #users
353+ createTable #users
349−-- ( serial `As` #id :*
354+ ( serial `As` #id :*
350−-- (text & notNullable) `As` #name :* Nil )
355+ (text & notNullable) `As` #name :* Nil )
351−-- ( primaryKey #id `As` #pk_users :* Nil ) >>>
356+ ( primaryKey #id `As` #pk_users :* Nil ) >>>
352−-- createTable #emails
357+ createTable #emails
353−-- ( serial `As` #id :*
358+ ( serial `As` #id :*
354−-- (int & notNullable) `As` #user_id :*
359+ (int & notNullable) `As` #user_id :*
355−-- (text & nullable) `As` #email :* Nil )
360+ (text & nullable) `As` #email :* Nil )
356−-- ( primaryKey #id `As` #pk_emails :*
361+ ( primaryKey #id `As` #pk_emails :*
357−-- foreignKey #user_id #users #id
362+ foreignKey #user_id #users #id
358−-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
363+ OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
359−-- in renderDefinition setup
364+in Data.ByteString.Char8.putStrLn $ renderDefinition setup
366+CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
361−-- "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 NULL, CONSTRAINT \"pk_emails\" PRIMARY KEY (\"id\"), CONSTRAINT \"fk_user_id\" FOREIGN KEY (\"user_id\") REFERENCES \"users\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE);"
367+CREATE TABLE "emails" ("id" serial, "user_id" int NOT NULL, "email" text NULL, CONSTRAINT "pk_emails" PRIMARY KEY ("id"), CONSTRAINT "fk_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
363−-- A `foreignKey` can even be a table self-reference.
369+A `foreignKey` can even be a table self-reference.
366−-- type Schema =
372+type Schema =
367−-- '[ "employees" ::: 'Table (
373+ '[ "employees" ::: 'Table (
368−-- '[ "employees_pk" ::: 'PrimaryKey '["id"]
374+ '[ "employees_pk" ::: 'PrimaryKey '["id"]
369−-- , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"]
375+ , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"]
371−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
377+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
372−-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
378+ , "name" ::: 'NoDef :=> 'NotNull 'PGtext
373−-- , "employer_id" ::: 'NoDef :=> 'Null 'PGint4
379+ , "employer_id" ::: 'NoDef :=> 'Null 'PGint4
380−-- setup :: Definition '[] Schema
386+ setup :: Definition '[] Schema
381−-- setup =
387+ setup =
382−-- createTable #employees
388+ createTable #employees
383−-- ( serial `As` #id :*
389+ ( serial `As` #id :*
384−-- (text & notNullable) `As` #name :*
390+ (text & notNullable) `As` #name :*
385−-- (integer & nullable) `As` #employer_id :* Nil )
391+ (integer & nullable) `As` #employer_id :* Nil )
386−-- ( primaryKey #id `As` #employees_pk :*
392+ ( primaryKey #id `As` #employees_pk :*
387−-- foreignKey #employer_id #employees #id
393+ foreignKey #employer_id #employees #id
388−-- OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
394+ OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
389−-- in renderDefinition setup
395+in Data.ByteString.Char8.putStrLn $ renderDefinition setup
391−-- "CREATE 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);"
397+CREATE 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);
393foreignKey
399foreignKey
394 :: (ForeignKeyed schema child parent
400 :: (ForeignKeyed schema child parent
395 table reftable
401 table reftable
@@ -481,8 +487,8 @@ DROP statements
481-- definition = dropTable #muh_table
487-- definition = dropTable #muh_table
484−-- >>> renderDefinition definition
490+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
485−-- "DROP TABLE \"muh_table\";"
491+-- DROP TABLE "muh_table";
487 :: Has table schema ('Table t)
493 :: Has table schema ('Table t)
488 => Alias table -- ^ table to remove
494 => Alias table -- ^ table to remove
@@ -507,8 +513,8 @@ alterTable tab alteration = UnsafeDefinition $
508-- | `alterTableRename` changes the name of a table from the schema.
514-- | `alterTableRename` changes the name of a table from the schema.
510−-- >>> renderDefinition $ alterTableRename #foo #bar
516+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ alterTableRename #foo #bar
511−-- "ALTER TABLE \"foo\" RENAME TO \"bar\";"
517+-- ALTER TABLE "foo" RENAME TO "bar";
512alterTableRename
518alterTableRename
513 :: (KnownSymbol table0, KnownSymbol table1)
519 :: (KnownSymbol table0, KnownSymbol table1)
514 => Alias table0 -- ^ table to rename
520 => Alias table0 -- ^ table to rename
@@ -535,9 +541,9 @@ newtype AlterTable
535-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
541-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
536-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
542-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
537-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
543-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
538−-- in renderDefinition definition
544+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
540−-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
546+-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
541addConstraint
547addConstraint
542 :: ( KnownSymbol alias
548 :: ( KnownSymbol alias
543 , Has tab schema ('Table table0)
549 , Has tab schema ('Table table0)
@@ -559,9 +565,9 @@ addConstraint alias constraint = UnsafeAlterTable $
559-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
565-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
560-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
566-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
561-- definition = alterTable #tab (dropConstraint #positive)
567-- definition = alterTable #tab (dropConstraint #positive)
562−-- in renderDefinition definition
568+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
564−-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
570+-- ALTER TABLE "tab" DROP CONSTRAINT "positive";
565dropConstraint
571dropConstraint
566 :: ( KnownSymbol constraint
572 :: ( KnownSymbol constraint
567 , Has tab schema ('Table table0)
573 , Has tab schema ('Table table0)
@@ -586,9 +592,9 @@ class AddColumn ty where
586 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
592 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
587 -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
593 -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
588 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
594 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
589− -- in renderDefinition definition
595+ -- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
591− -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text NULL DEFAULT E'foo';"
597+ -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL DEFAULT E'foo';
593 -- >>> :{
599 -- >>> :{
@@ -598,9 +604,9 @@ class AddColumn ty where
598 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
604 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
599 -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
605 -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
600 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
606 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
601− -- in renderDefinition definition
607+ -- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
603− -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text NULL;"
609+ -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
604 addColumn
610 addColumn
605 :: ( KnownSymbol column
611 :: ( KnownSymbol column
606 , Has tab schema ('Table table0)
612 , Has tab schema ('Table table0)
@@ -627,9 +633,9 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
627-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
633-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
628-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
634-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
629-- definition = alterTable #tab (dropColumn #col2)
635-- definition = alterTable #tab (dropColumn #col2)
630−-- in renderDefinition definition
636+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
632−-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
638+-- ALTER TABLE "tab" DROP COLUMN "col2";
633dropColumn
639dropColumn
634 :: ( KnownSymbol column
640 :: ( KnownSymbol column
635 , Has tab schema ('Table table0)
641 , Has tab schema ('Table table0)
@@ -648,9 +654,9 @@ dropColumn column = UnsafeAlterTable $
648-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
654-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
649-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
655-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
650-- definition = alterTable #tab (renameColumn #foo #bar)
656-- definition = alterTable #tab (renameColumn #foo #bar)
651−-- in renderDefinition definition
657+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
653−-- "ALTER TABLE \"tab\" RENAME COLUMN \"foo\" TO \"bar\";"
659+-- ALTER TABLE "tab" RENAME COLUMN "foo" TO "bar";
654renameColumn
660renameColumn
655 :: ( KnownSymbol column0
661 :: ( KnownSymbol column0
656 , KnownSymbol column1
662 , KnownSymbol column1
@@ -691,9 +697,9 @@ newtype AlterColumn (schema :: SchemaType) (ty0 :: ColumnType) (ty1 :: ColumnTyp
691-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
697-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
692-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
698-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
693-- definition = alterTable #tab (alterColumn #col (setDefault 5))
699-- definition = alterTable #tab (alterColumn #col (setDefault 5))
694−-- in renderDefinition definition
700+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
696−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
702+-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
697setDefault
703setDefault
698 :: Expression schema '[] 'Ungrouped '[] ty -- ^ default value to set
704 :: Expression schema '[] 'Ungrouped '[] ty -- ^ default value to set
699 -> AlterColumn schema (constraint :=> ty) ('Def :=> ty)
705 -> AlterColumn schema (constraint :=> ty) ('Def :=> ty)
@@ -708,9 +714,9 @@ setDefault expression = UnsafeAlterColumn $
708-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
714-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
709-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
715-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
710-- definition = alterTable #tab (alterColumn #col dropDefault)
716-- definition = alterTable #tab (alterColumn #col dropDefault)
711−-- in renderDefinition definition
717+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
713−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP DEFAULT;"
719+-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
714dropDefault :: AlterColumn schema ('Def :=> ty) ('NoDef :=> ty)
720dropDefault :: AlterColumn schema ('Def :=> ty) ('NoDef :=> ty)
715dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
721dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
@@ -724,9 +730,9 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
724-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
730-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
725-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
731-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
726-- definition = alterTable #tab (alterColumn #col setNotNull)
732-- definition = alterTable #tab (alterColumn #col setNotNull)
727−-- in renderDefinition definition
733+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
729−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET NOT NULL;"
735+-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
730setNotNull
736setNotNull
731 :: AlterColumn schema (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
737 :: AlterColumn schema (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
732setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
738setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
@@ -739,9 +745,9 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
739-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
745-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
740-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
746-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
741-- definition = alterTable #tab (alterColumn #col dropNotNull)
747-- definition = alterTable #tab (alterColumn #col dropNotNull)
742−-- in renderDefinition definition
748+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
744−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP NOT NULL;"
750+-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
745dropNotNull
751dropNotNull
746 :: AlterColumn schema (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
752 :: AlterColumn schema (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
747dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
753dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
@@ -757,9 +763,9 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
757-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
763-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
758-- definition =
764-- definition =
759-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
765-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
760−-- in renderDefinition definition
766+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
762−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" TYPE numeric NOT NULL;"
768+-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
763alterType :: ColumnTypeExpression schema ty -> AlterColumn schema ty0 ty
769alterType :: ColumnTypeExpression schema ty -> AlterColumn schema ty0 ty
764alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
770alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
@@ -772,10 +778,10 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
772-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
778-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
773-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
779-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
774-- definition =
780-- definition =
775−-- createView #bc (select (#b `As` #b :* #c `As` #c :* Nil) (from (table (#abc `As` #abc))))
781+-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
776−-- in renderDefinition definition
782+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
778−-- "CREATE VIEW \"bc\" AS SELECT \"b\" AS \"b\", \"c\" AS \"c\" FROM \"abc\" AS \"abc\";"
784+-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
779createView
785createView
780 :: KnownSymbol view
786 :: KnownSymbol view
781 => Alias view -- ^ the name of the table to add
787 => Alias view -- ^ the name of the table to add
@@ -795,9 +801,9 @@ createView alias query = UnsafeDefinition $
795-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
801-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
796-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
802-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
797-- definition = dropView #bc
803-- definition = dropView #bc
798−-- in renderDefinition definition
804+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
800−-- "DROP VIEW \"bc\";"
806+-- DROP VIEW "bc";
802 :: Has view schema ('View v)
808 :: Has view schema ('View v)
803 => Alias view -- ^ view to remove
809 => Alias view -- ^ view to remove
@@ -806,8 +812,8 @@ dropView v = UnsafeDefinition $ "DROP VIEW" <+> renderAlias v <> ";"
807-- | Enumerated types are created using the `createTypeEnum` command, for example
813-- | Enumerated types are created using the `createTypeEnum` command, for example
809−-- >>> renderDefinition $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
815+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
810−-- "CREATE TYPE \"mood\" AS ENUM ('sad', 'ok', 'happy');"
816+-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
811createTypeEnum
817createTypeEnum
812 :: (KnownSymbol enum, SOP.All KnownSymbol labels)
818 :: (KnownSymbol enum, SOP.All KnownSymbol labels)
813 => Alias enum
819 => Alias enum
@@ -824,8 +830,8 @@ createTypeEnum enum labels = UnsafeDefinition $
824-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
830-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
825-- >>> instance SOP.Generic Schwarma
831-- >>> instance SOP.Generic Schwarma
826-- >>> instance SOP.HasDatatypeInfo Schwarma
832-- >>> instance SOP.HasDatatypeInfo Schwarma
827−-- >>> renderDefinition $ createTypeEnumWith @Schwarma #schwarma
833+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeEnumWith @Schwarma #schwarma
828−-- "CREATE TYPE \"schwarma\" AS ENUM ('Beef', 'Lamb', 'Chicken');"
834+-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
829createTypeEnumWith
835createTypeEnumWith
830 :: forall hask enum schema.
836 :: forall hask enum schema.
831 ( SOP.Generic hask
837 ( SOP.Generic hask
@@ -841,8 +847,8 @@ createTypeEnumWith enum = createTypeEnum enum
841-- | `createTypeComposite` creates a composite type. The composite type is
847-- | `createTypeComposite` creates a composite type. The composite type is
842-- specified by a list of attribute names and data types.
848-- specified by a list of attribute names and data types.
844−-- >>> renderDefinition $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
850+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
845−-- "CREATE TYPE \"complex\" AS (\"real\" float8, \"imaginary\" float8);"
851+-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
846createTypeComposite
852createTypeComposite
847 :: (KnownSymbol ty, SOP.SListI fields)
853 :: (KnownSymbol ty, SOP.SListI fields)
848 => Alias ty
854 => Alias ty
@@ -863,8 +869,8 @@ createTypeComposite ty fields = UnsafeDefinition $
863-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
869-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
864-- >>> instance SOP.Generic Complex
870-- >>> instance SOP.Generic Complex
865-- >>> instance SOP.HasDatatypeInfo Complex
871-- >>> instance SOP.HasDatatypeInfo Complex
866−-- >>> renderDefinition $ createTypeCompositeWith @Complex #complex
872+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeCompositeWith @Complex #complex
867−-- "CREATE TYPE \"complex\" AS (\"real\" float8, \"imaginary\" float8);"
873+-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
868createTypeCompositeWith
874createTypeCompositeWith
869 :: forall hask ty schema.
875 :: forall hask ty schema.
870 ( ZipAliased (FieldNamesWith hask) (FieldTypesWith hask)
876 ( ZipAliased (FieldNamesWith hask) (FieldTypesWith hask)
@@ -884,8 +890,8 @@ createTypeCompositeWith ty = createTypeComposite ty $ zipAs
884-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
890-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
885-- >>> instance SOP.Generic Schwarma
891-- >>> instance SOP.Generic Schwarma
886-- >>> instance SOP.HasDatatypeInfo Schwarma
892-- >>> instance SOP.HasDatatypeInfo Schwarma
887−-- >>> renderDefinition (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
893+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
888−-- "DROP TYPE \"schwarma\";"
894+-- DROP TYPE "schwarma";
890 :: Has tydef schema ('Typedef ty)
896 :: Has tydef schema ('Typedef ty)
891 => Alias tydef
897 => Alias tydef