@@ -37,7 +37,6 @@ module Squeal.PostgreSQL.Expression
37 ( -- * Expression
37 ( -- * Expression
38 Expression (UnsafeExpression, renderExpression)
38 Expression (UnsafeExpression, renderExpression)
39 , HasParameter (param)
39 , HasParameter (param)
40− , GroupedBy (getGroup1, getGroup2)
41 -- ** Null
40 -- ** Null
@@ -178,7 +177,7 @@ values from primitive expression using arithmetic, logical,
178and other operations.
177and other operations.
180newtype Expression
179newtype Expression
181− (relation :: RelationsType)
180+ (relations :: RelationsType)
182 (grouping :: Grouping)
181 (grouping :: Grouping)
183 (params :: [NullityType])
182 (params :: [NullityType])
184 (ty :: NullityType)
183 (ty :: NullityType)
@@ -212,35 +211,9 @@ instance (HasUnique relation relations columns, Has column columns ty)
212 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
211 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
214instance (Has relation relations columns, Has column columns ty)
213instance (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
216 relation ! column = UnsafeExpression $
215 relation ! column = UnsafeExpression $
217 renderAlias relation <> "." <> renderAlias column
216 renderAlias relation <> "." <> renderAlias column
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.
223−class (KnownSymbol relation, KnownSymbol column)
224− => GroupedBy relation column bys where
226− :: (HasUnique relation relations columns, Has column columns ty)
228− -> Expression relations ('Grouped bys) params ty
229− getGroup1 column = UnsafeExpression $ renderAlias column
231− :: (Has relation relations columns, Has column columns ty)
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)
246 ( HasUnique relation relations columns
219 ( HasUnique relation relations columns
@@ -248,14 +221,16 @@ instance
248 , GroupedBy relation column bys
221 , GroupedBy relation column bys
249 ) => IsLabel column
222 ) => IsLabel column
250 (Expression relations ('Grouped bys) params ty) where
223 (Expression relations ('Grouped bys) params ty) where
251− fromLabel = getGroup1 (Alias @column)
224+ fromLabel = UnsafeExpression $ renderAlias (Alias @column)
254 ( Has relation relations columns
227 ( Has relation relations columns
255 , Has column columns ty
228 , Has column columns ty
256 , GroupedBy relation column bys
229 , GroupedBy relation column bys
257− ) => IsTableColumn relation column
230+ ) => IsQualified relation column
258− (Expression relations ('Grouped bys) params ty) where (!) = getGroup2
231+ (Expression relations ('Grouped bys) params ty) where
232+ relation ! column = UnsafeExpression $
233+ renderAlias relation <> "." <> renderAlias column
260-- | analagous to `Nothing`
235-- | analagous to `Nothing`
@@ -288,7 +263,7 @@ coalesce nullxs notNullx = UnsafeExpression $
288 "COALESCE" <> parenthesized (commaSeparated
263 "COALESCE" <> parenthesized (commaSeparated
289 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
264 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
291−-- | analagous to `fromMaybe` using @COALESCE@
266+-- | analagous to `Data.Maybe.fromMaybe` using @COALESCE@
293-- >>> renderExpression $ fromNull true null_
268-- >>> renderExpression $ fromNull true null_
294-- "COALESCE(NULL, TRUE)"
269-- "COALESCE(NULL, TRUE)"