on dev help sign in
scrap your nils!
06a2d7bEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -27,7 +27,7 @@ let
27 query :: Query '[]
27 query :: Query '[]
28 '[ 'NotNull 'PGint2, 'NotNull 'PGtext]
28 '[ 'NotNull 'PGint2, 'NotNull 'PGtext]
29 '["col1" ::: 'NotNull 'PGint2, "col2" ::: 'NotNull 'PGtext]
29 '["col1" ::: 'NotNull 'PGint2, "col2" ::: 'NotNull 'PGtext]
30− query = values_ (param @1 `As` #col1 :* param @2 `As` #col2 :* Nil)
30+ query = values_ (param @1 `as` #col1 :* param @2 `as` #col2)
31:}
31:}
32
32
33>>> :{
33>>> :{
@@ -88,7 +88,7 @@ let
88 querySchwarma :: Query Schema
88 querySchwarma :: Query Schema
89 '[ 'NotNull (EnumFrom Schwarma)]
89 '[ 'NotNull (EnumFrom Schwarma)]
90 '["fromOnly" ::: 'NotNull (EnumFrom Schwarma)]
90 '["fromOnly" ::: 'NotNull (EnumFrom Schwarma)]
91− querySchwarma = values_ (parameter @1 #schwarma `As` #fromOnly)
91+ querySchwarma = values_ (parameter @1 #schwarma `as` #fromOnly)
92:}
92:}
93
93
94>>> :{
94>>> :{
@@ -96,7 +96,7 @@ let
96 queryPerson :: Query Schema
96 queryPerson :: Query Schema
97 '[ 'NotNull (CompositeFrom Person)]
97 '[ 'NotNull (CompositeFrom Person)]
98 '["fromOnly" ::: 'NotNull (CompositeFrom Person)]
98 '["fromOnly" ::: 'NotNull (CompositeFrom Person)]
99− queryPerson = values_ (parameter @1 #person `As` #fromOnly :* Nil)
99+ queryPerson = values_ (parameter @1 #person `as` #fromOnly)
100:}
100:}
101
101
102And finally drop the types.
102And finally drop the types.
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1−1
@@ -396,7 +396,7 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
396-- (also called a composite value) using values for its member fields.
396-- (also called a composite value) using values for its member fields.
397--
397--
398-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
398-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
399−-- >>> let i = row (0 `As` #real :* 1 `As` #imaginary :* Nil) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
399+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
400-- >>> printSQL i
400-- >>> printSQL i
401-- ROW(0, 1)
401-- ROW(0, 1)
402row
402row
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+16−16
@@ -36,9 +36,9 @@ let
36 { name = "make users table"
36 { name = "make users table"
37 , up = void . define $
37 , up = void . define $
38 createTable #users
38 createTable #users
39− ( serial `As` #id :*
39+ ( serial `as` #id :*
40− (text & notNullable) `As` #name :* Nil )
40+ (text & notNullable) `as` #name )
41− ( primaryKey #id `As` #pk_users :* Nil )
41+ ( primaryKey #id `as` #pk_users )
42 , down = void . define $ dropTable #users
42 , down = void . define $ dropTable #users
43 }
43 }
44:}
44:}
@@ -51,12 +51,12 @@ let
51 { name = "make emails table"
51 { name = "make emails table"
52 , up = void . define $
52 , up = void . define $
53 createTable #emails
53 createTable #emails
54− ( serial `As` #id :*
54+ ( serial `as` #id :*
55− (int & notNullable) `As` #user_id :*
55+ (int & notNullable) `as` #user_id :*
56− (text & nullable) `As` #email :* Nil )
56+ (text & nullable) `as` #email )
57− ( primaryKey #id `As` #pk_emails :*
57+ ( primaryKey #id `as` #pk_emails :*
58 foreignKey #user_id #users #id
58 foreignKey #user_id #users #id
59− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
59+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
60 , down = void . define $ dropTable #emails
60 , down = void . define $ dropTable #emails
61 }
61 }
62:}
62:}
@@ -71,7 +71,7 @@ let
71 :: Has "schema_migrations" schema ('Table MigrationsTable)
71 :: Has "schema_migrations" schema ('Table MigrationsTable)
72 => PQ schema schema IO ()
72 => PQ schema schema IO ()
73 numMigrations = do
73 numMigrations = do
74− result <- runQuery (selectStar (from (table (#schema_migrations `As` #m))))
74+ result <- runQuery (selectStar (from (table (#schema_migrations `as` #m))))
75 num <- ntuples result
75 num <- ntuples result
76 liftBase $ print num
76 liftBase $ print num
77:}
77:}
@@ -285,18 +285,18 @@ createMigrations
285 => Definition schema schema
285 => Definition schema schema
286createMigrations =
286createMigrations =
287 createTableIfNotExists #schema_migrations
287 createTableIfNotExists #schema_migrations
288− ( (text & notNullable) `As` #name :*
288+ ( (text & notNullable) `as` #name :*
289 (timestampWithTimeZone & notNullable & default_ currentTimestamp)
289 (timestampWithTimeZone & notNullable & default_ currentTimestamp)
290− `As` #executed_at :* Nil )
290+ `as` #executed_at )
291− ( unique (#name :* Nil) `As` #migrations_unique_name :* Nil )
291+ ( unique #name `as` #migrations_unique_name )
292
292
293-- | Inserts a `Migration` into the `MigrationsTable`
293-- | Inserts a `Migration` into the `MigrationsTable`
294insertMigration
294insertMigration
295 :: Has "schema_migrations" schema ('Table MigrationsTable)
295 :: Has "schema_migrations" schema ('Table MigrationsTable)
296 => Manipulation schema '[ 'NotNull 'PGtext] '[]
296 => Manipulation schema '[ 'NotNull 'PGtext] '[]
297insertMigration = insertRow_ #schema_migrations
297insertMigration = insertRow_ #schema_migrations
298− ( Set (param @1) `As` #name :*
298+ ( Set (param @1) `as` #name :*
299− Default `As` #executed_at :* Nil )
299+ Default `as` #executed_at )
300
300
301-- | Deletes a `Migration` from the `MigrationsTable`
301-- | Deletes a `Migration` from the `MigrationsTable`
302deleteMigration
302deleteMigration
@@ -311,6 +311,6 @@ selectMigration
311 => Query schema '[ 'NotNull 'PGtext ]
311 => Query schema '[ 'NotNull 'PGtext ]
312 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
312 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
313selectMigration = select
313selectMigration = select
314− (#executed_at `As` #executed_at :* Nil)
314+ (#executed_at `as` #executed_at)
315− ( from (table (#schema_migrations `As` #m))
315+ ( from (table (#schema_migrations `as` #m))
316 & where_ (#name .== param @1))
316 & where_ (#name .== param @1))
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+12−12
@@ -123,7 +123,7 @@ let
123 , "col1" ::: 'NotNull 'PGint4 ]
123 , "col1" ::: 'NotNull 'PGint4 ]
124 query =
124 query =
125 select
125 select
126− ((#col1 + #col2) `As` #sum :* #col1 :* Nil)
126+ ((#col1 + #col2) `as` #sum :* #col1)
127 ( from (table #tab)
127 ( from (table #tab)
128 & where_ (#col1 .> #col2)
128 & where_ (#col1 .> #col2)
129 & where_ (#col2 .> 0) )
129 & where_ (#col2 .> 0) )
@@ -141,7 +141,7 @@ let
141 '["col" ::: 'Null 'PGint4]
141 '["col" ::: 'Null 'PGint4]
142 query =
142 query =
143 selectStar
143 selectStar
144− (from (subquery (selectStar (from (table #tab)) `As` #sub)))
144+ (from (subquery (selectStar (from (table #tab)) `as` #sub)))
145in printSQL query
145in printSQL query
146:}
146:}
147SELECT * FROM (SELECT * FROM "tab" AS "tab") AS "sub"
147SELECT * FROM (SELECT * FROM "tab" AS "tab") AS "sub"
@@ -186,8 +186,8 @@ let
186 '[ "sum" ::: 'NotNull 'PGint4
186 '[ "sum" ::: 'NotNull 'PGint4
187 , "col1" ::: 'NotNull 'PGint4 ]
187 , "col1" ::: 'NotNull 'PGint4 ]
188 query =
188 query =
189− select (sum_ #col2 `As` #sum :* #col1 :* Nil)
189+ select (sum_ #col2 `as` #sum :* #col1)
190− ( from (table (#tab `As` #table1))
190+ ( from (table (#tab `as` #table1))
191 & group (By #col1 :* Nil)
191 & group (By #col1 :* Nil)
192 & having (#col1 + sum_ #col2 .> 1) )
192 & having (#col1 + sum_ #col2 .> 1) )
193in printSQL query
193in printSQL query
@@ -240,13 +240,13 @@ let
240 , "shipper_name" ::: 'NotNull 'PGtext
240 , "shipper_name" ::: 'NotNull 'PGtext
241 ]
241 ]
242 query = select
242 query = select
243− ( #o ! #price `As` #order_price :*
243+ ( #o ! #price `as` #order_price :*
244− #c ! #name `As` #customer_name :*
244+ #c ! #name `as` #customer_name :*
245− #s ! #name `As` #shipper_name :* Nil )
245+ #s ! #name `as` #shipper_name )
246− ( from (table (#orders `As` #o)
246+ ( from (table (#orders `as` #o)
247− & innerJoin (table (#customers `As` #c))
247+ & innerJoin (table (#customers `as` #c))
248 (#o ! #customer_id .== #c ! #id)
248 (#o ! #customer_id .== #c ! #id)
249− & innerJoin (table (#shippers `As` #s))
249+ & innerJoin (table (#shippers `as` #s))
250 (#o ! #shipper_id .== #s ! #id)) )
250 (#o ! #shipper_id .== #s ! #id)) )
251in printSQL query
251in printSQL query
252:}
252:}
@@ -261,7 +261,7 @@ let
261 '[]
261 '[]
262 '["col" ::: 'Null 'PGint4]
262 '["col" ::: 'Null 'PGint4]
263 query = selectDotStar #t1
263 query = selectDotStar #t1
264− (from (table (#tab `As` #t1) & crossJoin (table (#tab `As` #t2))))
264+ (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
265in printSQL query
265in printSQL query
266:}
266:}
267SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
267SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
@@ -463,7 +463,7 @@ selectDistinctDotStar rel relations = UnsafeQuery $
463-- but it can be used on its own.
463-- but it can be used on its own.
464--
464--
465-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
465-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
466−-- >>> let query = values (1 `As` #a :* "one" `As` #b :* Nil) [] :: Query '[] '[] Row
466+-- >>> let query = values (1 `as` #a :* "one" `as` #b) [] :: Query '[] '[] Row
467-- >>> printSQL query
467-- >>> printSQL query
468-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
468-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
469values
469values
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+16−6
@@ -402,14 +402,24 @@ instance (alias0 ~ alias1, alias0 ~ alias2, KnownSymbol alias2)
402 => IsLabel alias0 (Aliased Alias (alias1 ::: alias2)) where
402 => IsLabel alias0 (Aliased Alias (alias1 ::: alias2)) where
403 fromLabel = fromLabel @alias2 `As` fromLabel @alias1
403 fromLabel = fromLabel @alias2 `As` fromLabel @alias1
404
404
405−class KnownSymbol alias => Aliasable expression alias aliased where
405+class KnownSymbol alias => Aliasable expression alias aliased
406+ | aliased -> expression
407+ , aliased -> alias
408+ where
406− as :: expression -> Alias alias -> aliased
409+ as :: expression -> Alias alias -> aliased
410+
407instance KnownSymbol alias => Aliasable
411instance KnownSymbol alias => Aliasable
412+ (expression ty)
413+ alias
408− (expression ty) alias (Aliased expression (alias ::: ty)) where as = As
414+ (Aliased expression (alias ::: ty))
415+ where as = As
409instance KnownSymbol alias => Aliasable
416instance KnownSymbol alias => Aliasable
417+ (expression ty)
418+ alias
410− (expression ty) alias (NP (Aliased expression) '[alias ::: ty])
419+ (NP (Aliased expression) '[alias ::: ty])
411− where
420+ where
412− expression `as` alias = expression `As` alias :* Nil
421+ expression `as` alias = expression `As` alias :* Nil
422+
413-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
423-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
414-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
424-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
415-- "Just AS \"an_int\""
425-- "Just AS \"an_int\""