on dev help sign in
scrap some more Nils
commit01a75e38bc93bb174c90edaca6456618dd469a71 authorEitan Chatav <eitan.chatav@gmail.com> dateMon 2 Jul 2018, 09:29 (8 years ago) parent55541b7
3 files changed+44−42
squeal-postgresql/src/Squeal/PostgreSQL.hs+16−16 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+24−24 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+4−2
squeal-postgresql/src/Squeal/PostgreSQL.hs+16−16
@@ -71,16 +71,16 @@ let
7171 setup :: Definition '[] Schema
7272 setup =
7373 createTable #users
74− ( serial `As` #id :*
75− (text & notNullable) `As` #name :* Nil )
76− ( primaryKey #id `As` #pk_users :* Nil ) >>>
74+ ( serial `as` #id :*
75+ (text & notNullable) `as` #name )
76+ ( primaryKey #id `as` #pk_users ) >>>
7777 createTable #emails
78− ( serial `As` #id :*
79− (int & notNullable) `As` #user_id :*
80− (text & nullable) `As` #email :* Nil )
81− ( primaryKey #id `As` #pk_emails :*
78+ ( serial `as` #id :*
79+ (int & notNullable) `as` #user_id :*
80+ (text & nullable) `as` #email )
81+ ( primaryKey #id `as` #pk_emails :*
8282 foreignKey #user_id #users #id
83− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
83+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
8484:}
8585
8686We can easily see the generated SQL is unsurprising looking.
@@ -119,17 +119,17 @@ of our inserts.
119119let
120120 insertUser :: Manipulation Schema '[ 'NotNull 'PGtext ] '[ "fromOnly" ::: 'NotNull 'PGint4 ]
121121 insertUser = insertRow #users
122− (Default `As` #id :* Set (param @1) `As` #name :* Nil)
123− OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
122+ (Default `as` #id :* Set (param @1) `as` #name)
123+ OnConflictDoNothing (Returning (#id `as` #fromOnly))
124124:}
125125
126126>>> :{
127127let
128128 insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
129129 insertEmail = insertRow #emails
130− ( Default `As` #id :*
131− Set (param @1) `As` #user_id :*
132− Set (param @2) `As` #email :* Nil )
130+ ( Default `as` #id :*
131+ Set (param @1) `as` #user_id :*
132+ Set (param @2) `as` #email )
133133 OnConflictDoNothing (Returning Nil)
134134:}
135135
@@ -149,9 +149,9 @@ let
149149 '[ "userName" ::: 'NotNull 'PGtext
150150 , "userEmail" ::: 'Null 'PGtext ]
151151 getUsers = select
152− (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* Nil)
153− ( from (table (#users `As` #u)
154− & innerJoin (table (#emails `As` #e))
152+ (#u ! #name `as` #userName :* #e ! #email `as` #userEmail)
153+ ( from (table (#users `as` #u)
154+ & innerJoin (table (#emails `as` #e))
155155 (#u ! #id .== #e ! #user_id)) )
156156:}
157157
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+24−24
@@ -244,9 +244,9 @@ type Schema = '[
244244let
245245 definition :: Definition '[] Schema
246246 definition = createTable #tab
247− ( (int & notNullable) `As` #a :*
248− (int & notNullable) `As` #b :* Nil )
249− ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
247+ ( (int & notNullable) `as` #a :*
248+ (int & notNullable) `as` #b )
249+ ( check (#a :* #b) (#a .> #b) `as` #inequality )
250250:}
251251
252252>>> printSQL definition
@@ -278,9 +278,9 @@ type Schema = '[
278278let
279279 definition :: Definition '[] Schema
280280 definition = createTable #tab
281− ( (int & nullable) `As` #a :*
282− (int & nullable) `As` #b :* Nil )
283− ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
281+ ( (int & nullable) `as` #a :*
282+ (int & nullable) `as` #b )
283+ ( unique (#a :* #b) `as` #uq_a_b )
284284:}
285285
286286>>> printSQL definition
@@ -311,9 +311,9 @@ type Schema = '[
311311let
312312 definition :: Definition '[] Schema
313313 definition = createTable #tab
314− ( serial `As` #id :*
315− (text & notNullable) `As` #name :* Nil )
316− ( primaryKey #id `As` #pk_id :* Nil )
314+ ( serial `as` #id :*
315+ (text & notNullable) `as` #name )
316+ ( primaryKey #id `as` #pk_id )
317317:}
318318
319319>>> printSQL definition
@@ -357,16 +357,16 @@ let
357357 setup :: Definition '[] Schema
358358 setup =
359359 createTable #users
360− ( serial `As` #id :*
361− (text & notNullable) `As` #name :* Nil )
362− ( primaryKey #id `As` #pk_users :* Nil ) >>>
360+ ( serial `as` #id :*
361+ (text & notNullable) `as` #name )
362+ ( primaryKey #id `as` #pk_users ) >>>
363363 createTable #emails
364− ( serial `As` #id :*
365− (int & notNullable) `As` #user_id :*
366− (text & nullable) `As` #email :* Nil )
367− ( primaryKey #id `As` #pk_emails :*
364+ ( serial `as` #id :*
365+ (int & notNullable) `as` #user_id :*
366+ (text & nullable) `as` #email )
367+ ( primaryKey #id `as` #pk_emails :*
368368 foreignKey #user_id #users #id
369− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
369+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
370370in printSQL setup
371371:}
372372CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
@@ -392,12 +392,12 @@ let
392392 setup :: Definition '[] Schema
393393 setup =
394394 createTable #employees
395− ( serial `As` #id :*
396− (text & notNullable) `As` #name :*
397− (integer & nullable) `As` #employer_id :* Nil )
398− ( primaryKey #id `As` #employees_pk :*
395+ ( serial `as` #id :*
396+ (text & notNullable) `as` #name :*
397+ (integer & nullable) `as` #employer_id )
398+ ( primaryKey #id `as` #employees_pk :*
399399 foreignKey #employer_id #employees #id
400− OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
400+ OnDeleteCascade OnUpdateCascade `as` #employees_employer_fk )
401401in printSQL setup
402402:}
403403CREATE 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
546546-- definition :: Definition
547547-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
548548-- '["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)))
550550-- in printSQL definition
551551-- :}
552552-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
@@ -784,7 +784,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
784784-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
785785-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
786786-- definition =
787−-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
787+-- createView #bc (select (#b :* #c) (from (table #abc)))
788788-- in printSQL definition
789789-- :}
790790-- 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
688688-- `label`s are used for enum terms. A `label` is called with
689689-- type application like `label @"beef"`.
690690class IsPGlabel (label :: Symbol) expr where label :: expr
691−instance label ~ label'
692− => IsPGlabel label (PGlabel label') where label = PGlabel
691+instance label ~ label1
692+ => IsPGlabel label (PGlabel label1) where label = PGlabel
693+instance label ~ label1
694+ => IsPGlabel label (NP PGlabel '[label1]) where label = PGlabel :* Nil
693695-- | A `PGlabel` unit type with an `IsPGlabel` instance
694696data PGlabel (label :: Symbol) = PGlabel
695697-- | Renders a label