@@ -129,8 +129,17 @@ CREATE statements
129129
130130>>> :set -XOverloadedLabels
131131>>> :{
132−printSQL $
133− createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
132+type Table = '[] :=>
133+ '[ "a" ::: 'NoDef :=> 'Null 'PGint4
134+ , "b" ::: 'NoDef :=> 'Null 'PGfloat4 ]
135+:}
136+
137+>>> :{
138+let
139+ setup :: Definition '[] '["tab" ::: 'Table Table]
140+ setup = createTable #tab
141+ (nullable int `as` #a :* nullable real `as` #b) Nil
142+in printSQL setup
134143:}
135144CREATE TABLE "tab" ("a" int NULL, "b" real NULL);
136145-}
@@ -155,12 +164,19 @@ Instead, the schema already has the table so if the table did not yet exist, the
155164the `Category` of `Definition`s.
156165
157166>>> :set -XOverloadedLabels -XTypeApplications
158−>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
167+>>> :{
168+type Table = '[] :=>
169+ '[ "a" ::: 'NoDef :=> 'Null 'PGint4
170+ , "b" ::: 'NoDef :=> 'Null 'PGfloat4 ]
171+:}
172+
159173>>> type Schema = '["tab" ::: 'Table Table]
174+
160175>>> :{
161176let
162177 setup :: Definition Schema Schema
163− setup = createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
178+ setup = createTableIfNotExists #tab
179+ (nullable int `as` #a :* nullable real `as` #b) Nil
164180in printSQL setup
165181:}
166182CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
@@ -244,9 +260,9 @@ type Schema = '[
244260let
245261 definition :: Definition '[] Schema
246262 definition = createTable #tab
247− ( (int & notNullable) `As` #a :*
248− (int & notNullable) `As` #b :* Nil )
249− ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
263+ ( (int & notNullable) `as` #a :*
264+ (int & notNullable) `as` #b )
265+ ( check (#a :* #b) (#a .> #b) `as` #inequality )
250266:}
251267
252268>>> printSQL definition
@@ -278,9 +294,9 @@ type Schema = '[
278294let
279295 definition :: Definition '[] Schema
280296 definition = createTable #tab
281− ( (int & nullable) `As` #a :*
282− (int & nullable) `As` #b :* Nil )
283− ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
297+ ( (int & nullable) `as` #a :*
298+ (int & nullable) `as` #b )
299+ ( unique (#a :* #b) `as` #uq_a_b )
284300:}
285301
286302>>> printSQL definition
@@ -311,9 +327,9 @@ type Schema = '[
311327let
312328 definition :: Definition '[] Schema
313329 definition = createTable #tab
314− ( serial `As` #id :*
315− (text & notNullable) `As` #name :* Nil )
316− ( primaryKey #id `As` #pk_id :* Nil )
330+ ( serial `as` #id :*
331+ (text & notNullable) `as` #name )
332+ ( primaryKey #id `as` #pk_id )
317333:}
318334
319335>>> printSQL definition
@@ -357,16 +373,16 @@ let
357373 setup :: Definition '[] Schema
358374 setup =
359375 createTable #users
360− ( serial `As` #id :*
361− (text & notNullable) `As` #name :* Nil )
362− ( primaryKey #id `As` #pk_users :* Nil ) >>>
376+ ( serial `as` #id :*
377+ (text & notNullable) `as` #name )
378+ ( primaryKey #id `as` #pk_users ) >>>
363379 createTable #emails
364− ( serial `As` #id :*
365− (int & notNullable) `As` #user_id :*
366− (text & nullable) `As` #email :* Nil )
367− ( primaryKey #id `As` #pk_emails :*
380+ ( serial `as` #id :*
381+ (int & notNullable) `as` #user_id :*
382+ (text & nullable) `as` #email )
383+ ( primaryKey #id `as` #pk_emails :*
368384 foreignKey #user_id #users #id
369− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
385+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
370386in printSQL setup
371387:}
372388CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
@@ -392,12 +408,12 @@ let
392408 setup :: Definition '[] Schema
393409 setup =
394410 createTable #employees
395− ( serial `As` #id :*
396− (text & notNullable) `As` #name :*
397− (integer & nullable) `As` #employer_id :* Nil )
398− ( primaryKey #id `As` #employees_pk :*
411+ ( serial `as` #id :*
412+ (text & notNullable) `as` #name :*
413+ (integer & nullable) `as` #employer_id )
414+ ( primaryKey #id `as` #employees_pk :*
399415 foreignKey #employer_id #employees #id
400− OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
416+ OnDeleteCascade OnUpdateCascade `as` #employees_employer_fk )
401417in printSQL setup
402418:}
403419CREATE 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);
@@ -546,7 +562,7 @@ newtype AlterTable
546562-- definition :: Definition
547563-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
548564-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
549−-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
565+-- definition = alterTable #tab (addConstraint #positive (check #col (#col .> 0)))
550566-- in printSQL definition
551567-- :}
552568-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
@@ -784,7 +800,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
784800-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
785801-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
786802-- definition =
787−-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
803+-- createView #bc (select (#b :* #c) (from (table #abc)))
788804-- in printSQL definition
789805-- :}
790806-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
@@ -818,7 +834,7 @@ dropView v = UnsafeDefinition $ "DROP VIEW" <+> renderAlias v <> ";"
818834
819835-- | Enumerated types are created using the `createTypeEnum` command, for example
820836--
821−-- >>> printSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
837+-- >>> printSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy")
822838-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
823839createTypeEnum
824840 :: (KnownSymbol enum, SOP.All KnownSymbol labels)
@@ -850,11 +866,20 @@ createTypeEnumFrom
850866createTypeEnumFrom enum = createTypeEnum enum
851867 (SOP.hpure label :: NP PGlabel (LabelsFrom hask))
852868
853−-- | `createTypeComposite` creates a composite type. The composite type is
854−-- specified by a list of attribute names and data types.
855−--
856−-- >>> printSQL $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
857−-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
869+{- | `createTypeComposite` creates a composite type. The composite type is
870+specified by a list of attribute names and data types.
871+
872+>>> type PGcomplex = 'PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
873+
874+>>> :{
875+let
876+ setup :: Definition '[] '["complex" ::: 'Typedef PGcomplex]
877+ setup = createTypeComposite #complex
878+ (float8 `as` #real :* float8 `as` #imaginary)
879+in printSQL setup
880+:}
881+CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
882+-}
858883createTypeComposite
859884 :: (KnownSymbol ty, SOP.SListI fields)
860885 => Alias ty