on dev help sign in
scrap some more Nils
01a75e3Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL.hs+16−16
@@ -71,16 +71,16 @@ let
71 setup :: Definition '[] Schema
71 setup :: Definition '[] Schema
72 setup =
72 setup =
73 createTable #users
73 createTable #users
74− ( serial `As` #id :*
74+ ( serial `as` #id :*
75− (text & notNullable) `As` #name :* Nil )
75+ (text & notNullable) `as` #name )
76− ( primaryKey #id `As` #pk_users :* Nil ) >>>
76+ ( primaryKey #id `as` #pk_users ) >>>
77 createTable #emails
77 createTable #emails
78− ( serial `As` #id :*
78+ ( serial `as` #id :*
79− (int & notNullable) `As` #user_id :*
79+ (int & notNullable) `as` #user_id :*
80− (text & nullable) `As` #email :* Nil )
80+ (text & nullable) `as` #email )
81− ( primaryKey #id `As` #pk_emails :*
81+ ( primaryKey #id `as` #pk_emails :*
82 foreignKey #user_id #users #id
82 foreignKey #user_id #users #id
83− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
83+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
84:}
84:}
85
85
86We can easily see the generated SQL is unsurprising looking.
86We can easily see the generated SQL is unsurprising looking.
@@ -119,17 +119,17 @@ of our inserts.
119let
119let
120 insertUser :: Manipulation Schema '[ 'NotNull 'PGtext ] '[ "fromOnly" ::: 'NotNull 'PGint4 ]
120 insertUser :: Manipulation Schema '[ 'NotNull 'PGtext ] '[ "fromOnly" ::: 'NotNull 'PGint4 ]
121 insertUser = insertRow #users
121 insertUser = insertRow #users
122− (Default `As` #id :* Set (param @1) `As` #name :* Nil)
122+ (Default `as` #id :* Set (param @1) `as` #name)
123− OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
123+ OnConflictDoNothing (Returning (#id `as` #fromOnly))
124:}
124:}
125
125
126>>> :{
126>>> :{
127let
127let
128 insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
128 insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
129 insertEmail = insertRow #emails
129 insertEmail = insertRow #emails
130− ( Default `As` #id :*
130+ ( Default `as` #id :*
131− Set (param @1) `As` #user_id :*
131+ Set (param @1) `as` #user_id :*
132− Set (param @2) `As` #email :* Nil )
132+ Set (param @2) `as` #email )
133 OnConflictDoNothing (Returning Nil)
133 OnConflictDoNothing (Returning Nil)
134:}
134:}
135
135
@@ -149,9 +149,9 @@ let
149 '[ "userName" ::: 'NotNull 'PGtext
149 '[ "userName" ::: 'NotNull 'PGtext
150 , "userEmail" ::: 'Null 'PGtext ]
150 , "userEmail" ::: 'Null 'PGtext ]
151 getUsers = select
151 getUsers = select
152− (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* Nil)
152+ (#u ! #name `as` #userName :* #e ! #email `as` #userEmail)
153− ( from (table (#users `As` #u)
153+ ( from (table (#users `as` #u)
154− & innerJoin (table (#emails `As` #e))
154+ & innerJoin (table (#emails `as` #e))
155 (#u ! #id .== #e ! #user_id)) )
155 (#u ! #id .== #e ! #user_id)) )
156:}
156:}
157
157
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+24−24
@@ -244,9 +244,9 @@ type Schema = '[
244let
244let
245 definition :: Definition '[] Schema
245 definition :: Definition '[] Schema
246 definition = createTable #tab
246 definition = createTable #tab
247− ( (int & notNullable) `As` #a :*
247+ ( (int & notNullable) `as` #a :*
248− (int & notNullable) `As` #b :* Nil )
248+ (int & notNullable) `as` #b )
249− ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
249+ ( check (#a :* #b) (#a .> #b) `as` #inequality )
250:}
250:}
251
251
252>>> printSQL definition
252>>> printSQL definition
@@ -278,9 +278,9 @@ type Schema = '[
278let
278let
279 definition :: Definition '[] Schema
279 definition :: Definition '[] Schema
280 definition = createTable #tab
280 definition = createTable #tab
281− ( (int & nullable) `As` #a :*
281+ ( (int & nullable) `as` #a :*
282− (int & nullable) `As` #b :* Nil )
282+ (int & nullable) `as` #b )
283− ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
283+ ( unique (#a :* #b) `as` #uq_a_b )
284:}
284:}
285
285
286>>> printSQL definition
286>>> printSQL definition
@@ -311,9 +311,9 @@ type Schema = '[
311let
311let
312 definition :: Definition '[] Schema
312 definition :: Definition '[] Schema
313 definition = createTable #tab
313 definition = createTable #tab
314− ( serial `As` #id :*
314+ ( serial `as` #id :*
315− (text & notNullable) `As` #name :* Nil )
315+ (text & notNullable) `as` #name )
316− ( primaryKey #id `As` #pk_id :* Nil )
316+ ( primaryKey #id `as` #pk_id )
317:}
317:}
318
318
319>>> printSQL definition
319>>> printSQL definition
@@ -357,16 +357,16 @@ let
357 setup :: Definition '[] Schema
357 setup :: Definition '[] Schema
358 setup =
358 setup =
359 createTable #users
359 createTable #users
360− ( serial `As` #id :*
360+ ( serial `as` #id :*
361− (text & notNullable) `As` #name :* Nil )
361+ (text & notNullable) `as` #name )
362− ( primaryKey #id `As` #pk_users :* Nil ) >>>
362+ ( primaryKey #id `as` #pk_users ) >>>
363 createTable #emails
363 createTable #emails
364− ( serial `As` #id :*
364+ ( serial `as` #id :*
365− (int & notNullable) `As` #user_id :*
365+ (int & notNullable) `as` #user_id :*
366− (text & nullable) `As` #email :* Nil )
366+ (text & nullable) `as` #email )
367− ( primaryKey #id `As` #pk_emails :*
367+ ( primaryKey #id `as` #pk_emails :*
368 foreignKey #user_id #users #id
368 foreignKey #user_id #users #id
369− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
369+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
370in printSQL setup
370in printSQL setup
371:}
371:}
372CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
372CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
@@ -392,12 +392,12 @@ let
392 setup :: Definition '[] Schema
392 setup :: Definition '[] Schema
393 setup =
393 setup =
394 createTable #employees
394 createTable #employees
395− ( serial `As` #id :*
395+ ( serial `as` #id :*
396− (text & notNullable) `As` #name :*
396+ (text & notNullable) `as` #name :*
397− (integer & nullable) `As` #employer_id :* Nil )
397+ (integer & nullable) `as` #employer_id )
398− ( primaryKey #id `As` #employees_pk :*
398+ ( primaryKey #id `as` #employees_pk :*
399 foreignKey #employer_id #employees #id
399 foreignKey #employer_id #employees #id
400− OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
400+ OnDeleteCascade OnUpdateCascade `as` #employees_employer_fk )
401in printSQL setup
401in printSQL setup
402:}
402:}
403CREATE 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);
403CREATE 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 +546,7 @@ newtype AlterTable
546-- definition :: Definition
546-- definition :: Definition
547-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
547-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
548-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
548-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
549−-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
549+-- definition = alterTable #tab (addConstraint #positive (check #col (#col .> 0)))
550-- in printSQL definition
550-- in printSQL definition
551-- :}
551-- :}
552-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
552-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
@@ -784,7 +784,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
784-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
784-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
785-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
785-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
786-- definition =
786-- definition =
787−-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
787+-- createView #bc (select (#b :* #c) (from (table #abc)))
788-- in printSQL definition
788-- in printSQL definition
789-- :}
789-- :}
790-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
790-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4−2
@@ -688,8 +688,10 @@ type family With
688-- `label`s are used for enum terms. A `label` is called with
688-- `label`s are used for enum terms. A `label` is called with
689-- type application like `label @"beef"`.
689-- type application like `label @"beef"`.
690class IsPGlabel (label :: Symbol) expr where label :: expr
690class IsPGlabel (label :: Symbol) expr where label :: expr
691−instance label ~ label'
691+instance label ~ label1
692+ => IsPGlabel label (PGlabel label1) where label = PGlabel
693+instance label ~ label1
692− => IsPGlabel label (PGlabel label') where label = PGlabel
694+ => IsPGlabel label (NP PGlabel '[label1]) where label = PGlabel :* Nil
693-- | A `PGlabel` unit type with an `IsPGlabel` instance
695-- | A `PGlabel` unit type with an `IsPGlabel` instance
694data PGlabel (label :: Symbol) = PGlabel
696data PGlabel (label :: Symbol) = PGlabel
695-- | Renders a label
697-- | Renders a label