@@ -750,7 +750,7 @@ instance RenderSQL (TableExpression outer commons grp schemas params from) where
750750from
751751 :: FromClause outer commons schemas params from -- ^ table reference
752752 -> TableExpression outer commons 'Ungrouped schemas params from
753−from tab = TableExpression tab [] NoGroups NoHaving [] [] []
753+from tab = TableExpression tab [] noGroups NoHaving [] [] []
754754
755755-- | A `where_` is an endomorphism of `TableExpression`s which adds a
756756-- search condition to the `whereClause`.
@@ -771,7 +771,7 @@ groupBy
771771groupBy bys rels = TableExpression
772772 { fromClause = fromClause rels
773773 , whereClause = whereClause rels
774− , groupByClause = Group bys
774+ , groupByClause = group bys
775775 , havingClause = Having []
776776 , orderByClause = []
777777 , limitClause = limitClause rels
@@ -985,19 +985,20 @@ instance (Has rel rels cols, Has col cols ty, bys ~ '[ '(rel, col)])
985985-- done on @NoGroups@ while all output `Expression`s must be aggregated
986986-- in @Group Nil@. In general, all output `Expression`s in the
987987-- complement of @bys@ must be aggregated in @Group bys@.
988−data GroupByClause grp from where
989− NoGroups :: GroupByClause 'Ungrouped from
990− Group
991− :: SListI bys
992− => NP (By from) bys
993− -> GroupByClause ('Grouped bys) from
994−
995−-- | Renders a `GroupByClause`.
988+newtype GroupByClause grp from = UnsafeGroupByClause
989+ { renderGroupByClause :: ByteString }
990+ deriving (GHC.Generic,Show,Eq,Ord,NFData)
996991instance RenderSQL (GroupByClause grp from) where
997− renderSQL = \case
998− NoGroups -> ""
999− Group Nil -> ""
1000− Group bys -> " GROUP BY" <+> renderCommaSeparated renderSQL bys
992+ renderSQL = renderGroupByClause
993+noGroups :: GroupByClause 'Ungrouped from
994+noGroups = UnsafeGroupByClause ""
995+group
996+ :: SListI bys
997+ => NP (By from) bys
998+ -> GroupByClause ('Grouped bys) from
999+group bys = UnsafeGroupByClause $ case bys of
1000+ Nil -> ""
1001+ bys' -> " GROUP BY" <+> renderCommaSeparated renderSQL bys'
10011002
10021003-- | A `HavingClause` is used to eliminate groups that are not of interest.
10031004-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`