on dev help sign in
aliasing instances

for singleton lists of expressions

commitc1102b242ace98a59124c54e17cd434bee68f566 authorEitan Chatav <eitan.chatav@gmail.com> dateFri 15 Feb 2019, 23:31 (8 years ago) parent6737890
2 files changed+23−1
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+22 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+1−1
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+22
@@ -292,6 +292,9 @@ param = parameter @n (pgtype @schemas)
292292instance (HasUnique tab from row, Has col row ty)
293293 => IsLabel col (Expression 'Ungrouped commons schemas params from ty) where
294294 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
295+instance (HasUnique tab from row, Has col row ty, tys ~ '[ty])
296+ => IsLabel col (NP (Expression 'Ungrouped commons schemas params from) tys) where
297+ fromLabel = fromLabel @col :* Nil
295298instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
296299 => IsLabel col
297300 (Aliased (Expression 'Ungrouped commons schemas params from) column) where
@@ -305,6 +308,9 @@ instance (Has tab from row, Has col row ty)
305308 => IsQualified tab col (Expression 'Ungrouped commons schemas params from ty) where
306309 tab ! col = UnsafeExpression $
307310 renderSQL tab <> "." <> renderSQL col
311+instance (Has tab from row, Has col row ty, tys ~ '[ty])
312+ => IsQualified tab col (NP (Expression 'Ungrouped commons schemas params from) tys) where
313+ tab ! col = tab ! col :* Nil
308314instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
309315 => IsQualified tab col
310316 (Aliased (Expression 'Ungrouped commons schemas params from) column) where
@@ -321,6 +327,14 @@ instance
321327 ) => IsLabel col
322328 (Expression ('Grouped bys) commons schemas params from ty) where
323329 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
330+instance
331+ ( HasUnique tab from row
332+ , Has col row ty
333+ , GroupedBy tab col bys
334+ , tys ~ '[ty]
335+ ) => IsLabel col
336+ (NP (Expression ('Grouped bys) commons schemas params from) tys) where
337+ fromLabel = fromLabel @col :* Nil
324338instance
325339 ( HasUnique tab from row
326340 , Has col row ty
@@ -346,6 +360,14 @@ instance
346360 (Expression ('Grouped bys) commons schemas params from ty) where
347361 tab ! col = UnsafeExpression $
348362 renderSQL tab <> "." <> renderSQL col
363+instance
364+ ( Has tab from row
365+ , Has col row ty
366+ , GroupedBy tab col bys
367+ , tys ~ '[ty]
368+ ) => IsQualified tab col
369+ (NP (Expression ('Grouped bys) commons schemas params from) tys) where
370+ tab ! col = tab ! col :* Nil
349371instance
350372 ( Has tab from row
351373 , Has col row ty
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+1−1
@@ -317,7 +317,7 @@ window function queries
317317let
318318 query :: Query '[] (Public Schema) '[] ["col1" ::: 'NotNull 'PGint4, "rank" ::: 'NotNull 'PGint8]
319319 query = select
320− (List #col1 & Also ((rank `as` #rank) `Over` (partitionBy (#col1 :* Nil) & orderBy [#col2 & Asc])))
320+ (#col1 & Also (rank `as` #rank `Over` (partitionBy #col1 & orderBy [#col2 & Asc])))
321321 (from (table #tab))
322322in printSQL query
323323:}