@@ -116,20 +116,21 @@ newtype Definition
116116instance Category Definition where
117117 id = UnsafeDefinition ";"
118118 ddl1 . ddl0 = UnsafeDefinition $
119− renderDefinition ddl0 <+> renderDefinition ddl1
119+ renderDefinition ddl0 <> "\n" <> renderDefinition ddl1
120120
121121{-----------------------------------------
122122CREATE statements
123123-----------------------------------------}
124124
125−-- | `createTable` adds a table to the schema.
126−--
127−-- >>> :set -XOverloadedLabels
128−-- >>> :{
129−-- renderDefinition $
130−-- createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
131−-- :}
132−-- "CREATE TABLE \"tab\" (\"a\" int NULL, \"b\" real NULL);"
125+{- | `createTable` adds a table to the schema.
126+
127+>>> :set -XOverloadedLabels
128+>>> :{
129+Data.ByteString.Char8.putStrLn . renderDefinition $
130+ createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
131+:}
132+CREATE TABLE "tab" ("a" int NULL, "b" real NULL);
133+-}
133134createTable
134135 :: ( KnownSymbol table
135136 , columns ~ (col ': cols)
@@ -145,18 +146,19 @@ createTable
145146createTable tab columns constraints = UnsafeDefinition $
146147 "CREATE TABLE" <+> renderCreation tab columns constraints
147148
148−-- | `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−-- `createTableIfNotExists` fixes this. Interestingly, this property makes it an idempotent in the `Category` `Definition`.
151−--
152−-- >>> :set -XOverloadedLabels -XTypeApplications
153−-- >>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
154−-- >>> type Schema = '["tab" ::: 'Table Table]
155−-- >>> :{
156−-- renderDefinition
157−-- (createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil :: Definition Schema Schema)
158−-- :}
159−-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int NULL, \"b\" real NULL);"
149+{-| `createTableIfNotExists` creates a table if it doesn't exist, but does not add it to the schema.
150+Instead, the schema already has the table so if the table did not yet exist, the schema was wrong.
151+`createTableIfNotExists` fixes this. Interestingly, this property makes it an idempotent in the `Category` `Definition`.
152+
153+>>> :set -XOverloadedLabels -XTypeApplications
154+>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
155+>>> type Schema = '["tab" ::: 'Table Table]
156+>>> :{
157+Data.ByteString.Char8.putStrLn $ renderDefinition
158+ (createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil :: Definition Schema Schema)
159+:}
160+CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
161+-}
160162createTableIfNotExists
161163 :: ( Has table schema ('Table (constraints :=> columns))
162164 , SOP.SListI columns
@@ -220,29 +222,30 @@ newtype TableConstraintExpression
220222 { renderTableConstraintExpression :: ByteString }
221223 deriving (GHC.Generic,Show,Eq,Ord,NFData)
222224
223−-- | A `check` constraint is the most generic `TableConstraint` type.
224−-- It allows you to specify that the value in a certain column must satisfy
225−-- a Boolean (truth-value) expression.
226−--
227−-- >>> :{
228−-- type Schema = '[
229−-- "tab" ::: 'Table ('[ "inequality" ::: 'Check '["a","b"]] :=> '[
230−-- "a" ::: 'NoDef :=> 'NotNull 'PGint4,
231−-- "b" ::: 'NoDef :=> 'NotNull 'PGint4
232−-- ])]
233−-- :}
234−--
235−-- >>> :{
236−-- let
237−-- definition :: Definition '[] Schema
238−-- definition = createTable #tab
239−-- ( (int & notNullable) `As` #a :*
240−-- (int & notNullable) `As` #b :* Nil )
241−-- ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
242−-- :}
243−--
244−-- >>> renderDefinition definition
245−-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
225+{-| A `check` constraint is the most generic `TableConstraint` type.
226+It allows you to specify that the value in a certain column must satisfy
227+a Boolean (truth-value) expression.
228+
229+>>> :{
230+type Schema = '[
231+ "tab" ::: 'Table ('[ "inequality" ::: 'Check '["a","b"]] :=> '[
232+ "a" ::: 'NoDef :=> 'NotNull 'PGint4,
233+ "b" ::: 'NoDef :=> 'NotNull 'PGint4
234+ ])]
235+:}
236+
237+>>> :{
238+let
239+ definition :: Definition '[] Schema
240+ definition = createTable #tab
241+ ( (int & notNullable) `As` #a :*
242+ (int & notNullable) `As` #b :* Nil )
243+ ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
244+:}
245+
246+>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
247+CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
248+-}
246249check
247250 :: ( Has alias schema ('Table table)
248251 , HasAll aliases (TableToRelation table) subcolumns )
@@ -254,28 +257,29 @@ check
254257check _cols condition = UnsafeTableConstraintExpression $
255258 "CHECK" <+> parenthesized (renderExpression condition)
256259
257−-- | 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.
259−--
260−-- >>> :{
261−-- type Schema = '[
262−-- "tab" ::: 'Table( '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[
263−-- "a" ::: 'NoDef :=> 'Null 'PGint4,
264−-- "b" ::: 'NoDef :=> 'Null 'PGint4
265−-- ])]
266−-- :}
267−--
268−-- >>> :{
269−-- let
270−-- definition :: Definition '[] Schema
271−-- definition = createTable #tab
272−-- ( (int & nullable) `As` #a :*
273−-- (int & nullable) `As` #b :* Nil )
274−-- ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
275−-- :}
276−--
277−-- >>> renderDefinition definition
278−-- "CREATE TABLE \"tab\" (\"a\" int NULL, \"b\" int NULL, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
260+{-| A `unique` constraint ensure that the data contained in a column,
261+or a group of columns, is unique among all the rows in the table.
262+
263+>>> :{
264+type Schema = '[
265+ "tab" ::: 'Table( '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[
266+ "a" ::: 'NoDef :=> 'Null 'PGint4,
267+ "b" ::: 'NoDef :=> 'Null 'PGint4
268+ ])]
269+:}
270+
271+>>> :{
272+let
273+ definition :: Definition '[] Schema
274+ definition = createTable #tab
275+ ( (int & nullable) `As` #a :*
276+ (int & nullable) `As` #b :* Nil )
277+ ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
278+:}
279+
280+>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
281+CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
282+-}
279283unique
280284 :: ( Has alias schema ('Table table)
281285 , HasAll aliases (TableToRelation table) subcolumns )
@@ -285,29 +289,30 @@ unique
285289unique columns = UnsafeTableConstraintExpression $
286290 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
287291
288−-- | A `primaryKey` constraint indicates that a column, or group of columns,
289−-- can be used as a unique identifier for rows in the table.
290−-- This requires that the values be both unique and not null.
291−--
292−-- >>> :{
293−-- type Schema = '[
294−-- "tab" ::: 'Table ('[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[
295−-- "id" ::: 'Def :=> 'NotNull 'PGint4,
296−-- "name" ::: 'NoDef :=> 'NotNull 'PGtext
297−-- ])]
298−-- :}
299−--
300−-- >>> :{
301−-- let
302−-- definition :: Definition '[] Schema
303−-- definition = createTable #tab
304−-- ( serial `As` #id :*
305−-- (text & notNullable) `As` #name :* Nil )
306−-- ( primaryKey #id `As` #pk_id :* Nil )
307−-- :}
308−--
309−-- >>> renderDefinition definition
310−-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
292+{-| A `primaryKey` constraint indicates that a column, or group of columns,
293+can be used as a unique identifier for rows in the table.
294+This requires that the values be both unique and not null.
295+
296+>>> :{
297+type Schema = '[
298+ "tab" ::: 'Table ('[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[
299+ "id" ::: 'Def :=> 'NotNull 'PGint4,
300+ "name" ::: 'NoDef :=> 'NotNull 'PGtext
301+ ])]
302+:}
303+
304+>>> :{
305+let
306+ definition :: Definition '[] Schema
307+ definition = createTable #tab
308+ ( serial `As` #id :*
309+ (text & notNullable) `As` #name :* Nil )
310+ ( primaryKey #id `As` #pk_id :* Nil )
311+:}
312+
313+>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
314+CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
315+-}
311316primaryKey
312317 :: ( Has alias schema ('Table table)
313318 , HasAll aliases (TableToColumns table) subcolumns
@@ -318,78 +323,79 @@ primaryKey
318323primaryKey columns = UnsafeTableConstraintExpression $
319324 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
320325
321−-- | A `foreignKey` specifies that the values in a column
322−-- (or a group of columns) must match the values appearing in some row of
323−-- another table. We say this maintains the referential integrity
324−-- between two related tables.
325−--
326−-- >>> :{
327−-- type Schema =
328−-- '[ "users" ::: 'Table (
329−-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
330−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
331−-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
332−-- ])
333−-- , "emails" ::: 'Table (
334−-- '[ "pk_emails" ::: 'PrimaryKey '["id"]
335−-- , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
336−-- ] :=>
337−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
338−-- , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
339−-- , "email" ::: 'NoDef :=> 'Null 'PGtext
340−-- ])
341−-- ]
342−-- :}
343−--
344−-- >>> :{
345−-- let
346−-- setup :: Definition '[] Schema
347−-- setup =
348−-- createTable #users
349−-- ( serial `As` #id :*
350−-- (text & notNullable) `As` #name :* Nil )
351−-- ( primaryKey #id `As` #pk_users :* Nil ) >>>
352−-- createTable #emails
353−-- ( serial `As` #id :*
354−-- (int & notNullable) `As` #user_id :*
355−-- (text & nullable) `As` #email :* Nil )
356−-- ( primaryKey #id `As` #pk_emails :*
357−-- foreignKey #user_id #users #id
358−-- OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
359−-- in renderDefinition setup
360−-- :}
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);"
362−--
363−-- A `foreignKey` can even be a table self-reference.
364−--
365−-- >>> :{
366−-- type Schema =
367−-- '[ "employees" ::: 'Table (
368−-- '[ "employees_pk" ::: 'PrimaryKey '["id"]
369−-- , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"]
370−-- ] :=>
371−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
372−-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
373−-- , "employer_id" ::: 'NoDef :=> 'Null 'PGint4
374−-- ])
375−-- ]
376−-- :}
377−--
378−-- >>> :{
379−-- let
380−-- setup :: Definition '[] Schema
381−-- setup =
382−-- createTable #employees
383−-- ( serial `As` #id :*
384−-- (text & notNullable) `As` #name :*
385−-- (integer & nullable) `As` #employer_id :* Nil )
386−-- ( primaryKey #id `As` #employees_pk :*
387−-- foreignKey #employer_id #employees #id
388−-- OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
389−-- in renderDefinition setup
390−-- :}
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);"
392−--
326+{-| A `foreignKey` specifies that the values in a column
327+(or a group of columns) must match the values appearing in some row of
328+another table. We say this maintains the referential integrity
329+between two related tables.
330+
331+>>> :{
332+type Schema =
333+ '[ "users" ::: 'Table (
334+ '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
335+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
336+ , "name" ::: 'NoDef :=> 'NotNull 'PGtext
337+ ])
338+ , "emails" ::: 'Table (
339+ '[ "pk_emails" ::: 'PrimaryKey '["id"]
340+ , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
341+ ] :=>
342+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
343+ , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
344+ , "email" ::: 'NoDef :=> 'Null 'PGtext
345+ ])
346+ ]
347+:}
348+
349+>>> :{
350+let
351+ setup :: Definition '[] Schema
352+ setup =
353+ createTable #users
354+ ( serial `As` #id :*
355+ (text & notNullable) `As` #name :* Nil )
356+ ( primaryKey #id `As` #pk_users :* Nil ) >>>
357+ createTable #emails
358+ ( serial `As` #id :*
359+ (int & notNullable) `As` #user_id :*
360+ (text & nullable) `As` #email :* Nil )
361+ ( primaryKey #id `As` #pk_emails :*
362+ foreignKey #user_id #users #id
363+ OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
364+in Data.ByteString.Char8.putStrLn $ renderDefinition setup
365+:}
366+CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
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);
368+
369+A `foreignKey` can even be a table self-reference.
370+
371+>>> :{
372+type Schema =
373+ '[ "employees" ::: 'Table (
374+ '[ "employees_pk" ::: 'PrimaryKey '["id"]
375+ , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"]
376+ ] :=>
377+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
378+ , "name" ::: 'NoDef :=> 'NotNull 'PGtext
379+ , "employer_id" ::: 'NoDef :=> 'Null 'PGint4
380+ ])
381+ ]
382+:}
383+
384+>>> :{
385+let
386+ setup :: Definition '[] Schema
387+ setup =
388+ createTable #employees
389+ ( serial `As` #id :*
390+ (text & notNullable) `As` #name :*
391+ (integer & nullable) `As` #employer_id :* Nil )
392+ ( primaryKey #id `As` #employees_pk :*
393+ foreignKey #employer_id #employees #id
394+ OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
395+in Data.ByteString.Char8.putStrLn $ renderDefinition setup
396+:}
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);
398+-}
393399foreignKey
394400 :: (ForeignKeyed schema child parent
395401 table reftable
@@ -481,8 +487,8 @@ DROP statements
481487-- definition = dropTable #muh_table
482488-- :}
483489--
484−-- >>> renderDefinition definition
485−-- "DROP TABLE \"muh_table\";"
490+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
491+-- DROP TABLE "muh_table";
486492dropTable
487493 :: Has table schema ('Table t)
488494 => Alias table -- ^ table to remove
@@ -507,8 +513,8 @@ alterTable tab alteration = UnsafeDefinition $
507513
508514-- | `alterTableRename` changes the name of a table from the schema.
509515--
510−-- >>> renderDefinition $ alterTableRename #foo #bar
511−-- "ALTER TABLE \"foo\" RENAME TO \"bar\";"
516+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ alterTableRename #foo #bar
517+-- ALTER TABLE "foo" RENAME TO "bar";
512518alterTableRename
513519 :: (KnownSymbol table0, KnownSymbol table1)
514520 => Alias table0 -- ^ table to rename
@@ -535,9 +541,9 @@ newtype AlterTable
535541-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
536542-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
537543-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
538−-- in renderDefinition definition
544+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
539545-- :}
540−-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
546+-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
541547addConstraint
542548 :: ( KnownSymbol alias
543549 , Has tab schema ('Table table0)
@@ -559,9 +565,9 @@ addConstraint alias constraint = UnsafeAlterTable $
559565-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
560566-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
561567-- definition = alterTable #tab (dropConstraint #positive)
562−-- in renderDefinition definition
568+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
563569-- :}
564−-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
570+-- ALTER TABLE "tab" DROP CONSTRAINT "positive";
565571dropConstraint
566572 :: ( KnownSymbol constraint
567573 , Has tab schema ('Table table0)
@@ -586,9 +592,9 @@ class AddColumn ty where
586592 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
587593 -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
588594 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
589− -- in renderDefinition definition
595+ -- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
590596 -- :}
591− -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text NULL DEFAULT E'foo';"
597+ -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL DEFAULT E'foo';
592598 --
593599 -- >>> :{
594600 -- let
@@ -598,9 +604,9 @@ class AddColumn ty where
598604 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
599605 -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
600606 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
601− -- in renderDefinition definition
607+ -- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
602608 -- :}
603− -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text NULL;"
609+ -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
604610 addColumn
605611 :: ( KnownSymbol column
606612 , Has tab schema ('Table table0)
@@ -627,9 +633,9 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
627633-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
628634-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
629635-- definition = alterTable #tab (dropColumn #col2)
630−-- in renderDefinition definition
636+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
631637-- :}
632−-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
638+-- ALTER TABLE "tab" DROP COLUMN "col2";
633639dropColumn
634640 :: ( KnownSymbol column
635641 , Has tab schema ('Table table0)
@@ -648,9 +654,9 @@ dropColumn column = UnsafeAlterTable $
648654-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
649655-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
650656-- definition = alterTable #tab (renameColumn #foo #bar)
651−-- in renderDefinition definition
657+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
652658-- :}
653−-- "ALTER TABLE \"tab\" RENAME COLUMN \"foo\" TO \"bar\";"
659+-- ALTER TABLE "tab" RENAME COLUMN "foo" TO "bar";
654660renameColumn
655661 :: ( KnownSymbol column0
656662 , KnownSymbol column1
@@ -691,9 +697,9 @@ newtype AlterColumn (schema :: SchemaType) (ty0 :: ColumnType) (ty1 :: ColumnTyp
691697-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
692698-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
693699-- definition = alterTable #tab (alterColumn #col (setDefault 5))
694−-- in renderDefinition definition
700+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
695701-- :}
696−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
702+-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
697703setDefault
698704 :: Expression schema '[] 'Ungrouped '[] ty -- ^ default value to set
699705 -> AlterColumn schema (constraint :=> ty) ('Def :=> ty)
@@ -708,9 +714,9 @@ setDefault expression = UnsafeAlterColumn $
708714-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
709715-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
710716-- definition = alterTable #tab (alterColumn #col dropDefault)
711−-- in renderDefinition definition
717+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
712718-- :}
713−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP DEFAULT;"
719+-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
714720dropDefault :: AlterColumn schema ('Def :=> ty) ('NoDef :=> ty)
715721dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
716722
@@ -724,9 +730,9 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
724730-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
725731-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
726732-- definition = alterTable #tab (alterColumn #col setNotNull)
727−-- in renderDefinition definition
733+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
728734-- :}
729−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET NOT NULL;"
735+-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
730736setNotNull
731737 :: AlterColumn schema (constraint :=> 'Null ty) (constraint :=> 'NotNull ty)
732738setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
@@ -739,9 +745,9 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
739745-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
740746-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
741747-- definition = alterTable #tab (alterColumn #col dropNotNull)
742−-- in renderDefinition definition
748+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
743749-- :}
744−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" DROP NOT NULL;"
750+-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
745751dropNotNull
746752 :: AlterColumn schema (constraint :=> 'NotNull ty) (constraint :=> 'Null ty)
747753dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
@@ -757,9 +763,9 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
757763-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
758764-- definition =
759765-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
760−-- in renderDefinition definition
766+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
761767-- :}
762−-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" TYPE numeric NOT NULL;"
768+-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
763769alterType :: ColumnTypeExpression schema ty -> AlterColumn schema ty0 ty
764770alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
765771
@@ -772,10 +778,10 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
772778-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
773779-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
774780-- definition =
775−-- createView #bc (select (#b `As` #b :* #c `As` #c :* Nil) (from (table (#abc `As` #abc))))
776−-- in renderDefinition definition
781+-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
782+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
777783-- :}
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";
779785createView
780786 :: KnownSymbol view
781787 => Alias view -- ^ the name of the table to add
@@ -795,9 +801,9 @@ createView alias query = UnsafeDefinition $
795801-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
796802-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
797803-- definition = dropView #bc
798−-- in renderDefinition definition
804+-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
799805-- :}
800−-- "DROP VIEW \"bc\";"
806+-- DROP VIEW "bc";
801807dropView
802808 :: Has view schema ('View v)
803809 => Alias view -- ^ view to remove
@@ -806,8 +812,8 @@ dropView v = UnsafeDefinition $ "DROP VIEW" <+> renderAlias v <> ";"
806812
807813-- | Enumerated types are created using the `createTypeEnum` command, for example
808814--
809−-- >>> renderDefinition $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
810−-- "CREATE TYPE \"mood\" AS ENUM ('sad', 'ok', 'happy');"
815+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
816+-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
811817createTypeEnum
812818 :: (KnownSymbol enum, SOP.All KnownSymbol labels)
813819 => Alias enum
@@ -824,8 +830,8 @@ createTypeEnum enum labels = UnsafeDefinition $
824830-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
825831-- >>> instance SOP.Generic Schwarma
826832-- >>> instance SOP.HasDatatypeInfo Schwarma
827−-- >>> renderDefinition $ createTypeEnumWith @Schwarma #schwarma
828−-- "CREATE TYPE \"schwarma\" AS ENUM ('Beef', 'Lamb', 'Chicken');"
833+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeEnumWith @Schwarma #schwarma
834+-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
829835createTypeEnumWith
830836 :: forall hask enum schema.
831837 ( SOP.Generic hask
@@ -841,8 +847,8 @@ createTypeEnumWith enum = createTypeEnum enum
841847-- | `createTypeComposite` creates a composite type. The composite type is
842848-- specified by a list of attribute names and data types.
843849--
844−-- >>> renderDefinition $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
845−-- "CREATE TYPE \"complex\" AS (\"real\" float8, \"imaginary\" float8);"
850+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
851+-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
846852createTypeComposite
847853 :: (KnownSymbol ty, SOP.SListI fields)
848854 => Alias ty
@@ -863,8 +869,8 @@ createTypeComposite ty fields = UnsafeDefinition $
863869-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
864870-- >>> instance SOP.Generic Complex
865871-- >>> instance SOP.HasDatatypeInfo Complex
866−-- >>> renderDefinition $ createTypeCompositeWith @Complex #complex
867−-- "CREATE TYPE \"complex\" AS (\"real\" float8, \"imaginary\" float8);"
872+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeCompositeWith @Complex #complex
873+-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
868874createTypeCompositeWith
869875 :: forall hask ty schema.
870876 ( ZipAliased (FieldNamesWith hask) (FieldTypesWith hask)
@@ -884,8 +890,8 @@ createTypeCompositeWith ty = createTypeComposite ty $ zipAs
884890-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
885891-- >>> instance SOP.Generic Schwarma
886892-- >>> instance SOP.HasDatatypeInfo Schwarma
887−-- >>> renderDefinition (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
888−-- "DROP TYPE \"schwarma\";"
893+-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
894+-- DROP TYPE "schwarma";
889895dropType
890896 :: Has tydef schema ('Typedef ty)
891897 => Alias tydef