on dev help sign in
aliasing instances
c1102b2Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+22
@@ -292,6 +292,9 @@ param = parameter @n (pgtype @schemas)
292instance (HasUnique tab from row, Has col row ty)
292instance (HasUnique tab from row, Has col row ty)
293 => IsLabel col (Expression 'Ungrouped commons schemas params from ty) where
293 => IsLabel col (Expression 'Ungrouped commons schemas params from ty) where
294 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
294 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
295instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
298instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
296 => IsLabel col
299 => IsLabel col
297 (Aliased (Expression 'Ungrouped commons schemas params from) column) where
300 (Aliased (Expression 'Ungrouped commons schemas params from) column) where
@@ -305,6 +308,9 @@ instance (Has tab from row, Has col row ty)
305 => IsQualified tab col (Expression 'Ungrouped commons schemas params from ty) where
308 => IsQualified tab col (Expression 'Ungrouped commons schemas params from ty) where
306 tab ! col = UnsafeExpression $
309 tab ! col = UnsafeExpression $
307 renderSQL tab <> "." <> renderSQL col
310 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
308instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
314instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
309 => IsQualified tab col
315 => IsQualified tab col
310 (Aliased (Expression 'Ungrouped commons schemas params from) column) where
316 (Aliased (Expression 'Ungrouped commons schemas params from) column) where
@@ -321,6 +327,14 @@ instance
321 ) => IsLabel col
327 ) => IsLabel col
322 (Expression ('Grouped bys) commons schemas params from ty) where
328 (Expression ('Grouped bys) commons schemas params from ty) where
323 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
329 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
324instance
338instance
325 ( HasUnique tab from row
339 ( HasUnique tab from row
326 , Has col row ty
340 , Has col row ty
@@ -346,6 +360,14 @@ instance
346 (Expression ('Grouped bys) commons schemas params from ty) where
360 (Expression ('Grouped bys) commons schemas params from ty) where
347 tab ! col = UnsafeExpression $
361 tab ! col = UnsafeExpression $
348 renderSQL tab <> "." <> renderSQL col
362 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
349instance
371instance
350 ( Has tab from row
372 ( Has tab from row
351 , Has col row ty
373 , Has col row ty
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+1−1
@@ -317,7 +317,7 @@ window function queries
317let
317let
318 query :: Query '[] (Public Schema) '[] ["col1" ::: 'NotNull 'PGint4, "rank" ::: 'NotNull 'PGint8]
318 query :: Query '[] (Public Schema) '[] ["col1" ::: 'NotNull 'PGint4, "rank" ::: 'NotNull 'PGint8]
319 query = select
319 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])))
321 (from (table #tab))
321 (from (table #tab))
322in printSQL query
322in printSQL query
323:}
323:}