@@ -37,7 +37,6 @@ module Squeal.PostgreSQL.Expression
3737 ( -- * Expression
3838 Expression (UnsafeExpression, renderExpression)
3939 , HasParameter (param)
40− , GroupedBy (getGroup1, getGroup2)
4140 -- ** Null
4241 , null_
4342 , unNull
@@ -178,7 +177,7 @@ values from primitive expression using arithmetic, logical,
178177and other operations.
179178-}
180179newtype Expression
181− (relation :: RelationsType)
180+ (relations :: RelationsType)
182181 (grouping :: Grouping)
183182 (params :: [NullityType])
184183 (ty :: NullityType)
@@ -212,35 +211,9 @@ instance (HasUnique relation relations columns, Has column columns ty)
212211 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
213212
214213instance (Has relation relations columns, Has column columns ty)
215− => IsTableColumn relation column (Expression relations 'Ungrouped params ty) where
214+ => IsQualified relation column (Expression relations 'Ungrouped params ty) where
216215 relation ! column = UnsafeExpression $
217216 renderAlias relation <> "." <> renderAlias column
218−
219−{- | A `GroupedBy` constraint indicates that a table qualified column is
220−a member of the auxiliary namespace created by @GROUP BY@ clauses and thus,
221−may be called in an output `Expression` without aggregating.
222−-}
223−class (KnownSymbol relation, KnownSymbol column)
224− => GroupedBy relation column bys where
225− getGroup1
226− :: (HasUnique relation relations columns, Has column columns ty)
227− => Alias column
228− -> Expression relations ('Grouped bys) params ty
229− getGroup1 column = UnsafeExpression $ renderAlias column
230− getGroup2
231− :: (Has relation relations columns, Has column columns ty)
232− => Alias relation
233− -> Alias column
234− -> Expression relations ('Grouped bys) params ty
235− getGroup2 relation column = UnsafeExpression $
236− renderAlias relation <> "." <> renderAlias column
237−instance {-# OVERLAPPING #-} (KnownSymbol relation, KnownSymbol column)
238− => GroupedBy relation column ('(table,column) ': bys)
239−instance {-# OVERLAPPABLE #-}
240− ( KnownSymbol relation
241− , KnownSymbol column
242− , GroupedBy relation column bys
243− ) => GroupedBy relation column (tabcol ': bys)
244217
245218instance
246219 ( HasUnique relation relations columns
@@ -248,14 +221,16 @@ instance
248221 , GroupedBy relation column bys
249222 ) => IsLabel column
250223 (Expression relations ('Grouped bys) params ty) where
251− fromLabel = getGroup1 (Alias @column)
224+ fromLabel = UnsafeExpression $ renderAlias (Alias @column)
252225
253226instance
254227 ( Has relation relations columns
255228 , Has column columns ty
256229 , GroupedBy relation column bys
257− ) => IsTableColumn relation column
258− (Expression relations ('Grouped bys) params ty) where (!) = getGroup2
230+ ) => IsQualified relation column
231+ (Expression relations ('Grouped bys) params ty) where
232+ relation ! column = UnsafeExpression $
233+ renderAlias relation <> "." <> renderAlias column
259234
260235-- | analagous to `Nothing`
261236--
@@ -288,7 +263,7 @@ coalesce nullxs notNullx = UnsafeExpression $
288263 "COALESCE" <> parenthesized (commaSeparated
289264 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
290265
291−-- | analagous to `fromMaybe` using @COALESCE@
266+-- | analagous to `Data.Maybe.fromMaybe` using @COALESCE@
292267--
293268-- >>> renderExpression $ fromNull true null_
294269-- "COALESCE(NULL, TRUE)"