Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ instance
<> selectModifier
<> mkMaybeClause @(Where t) q.whereQ
<> toClickhouseQuery @(GroupBy a gr) groupBy
<> mkMaybeClause @(Having t) (q.havingQ <&> ($ cols))
<> mkMaybeClause @(OrderBy ord) (q.orderByQ <&> ($ cols))
<> mkMaybeClause @Limit q.limitQ
<> mkMaybeClause @Offset q.offsetQ
Expand Down Expand Up @@ -121,6 +122,9 @@ instance ClickhouseQuery gr => ClickhouseQuery (GroupBy a gr) where
toClickhouseQuery Aggregate = mempty
toClickhouseQuery NotGrouped = mempty

instance ClickhouseTable t => ClickhouseQuery (Having t) where
toClickhouseQuery (Having clause) = " HAVING " <> addBrackets (toClickhouseQuery @(Clause t) clause)

instance ClickhouseTable t => ClickhouseQuery (Column a t value) where
toClickhouseQuery = fromString . showColumn

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ data Term value where

newtype Where table = Where (Clause table)

newtype Having table = Having (Clause table)

class IsGroupColumns cols where
type GroupColumnsType cols
groupColumns :: cols -> GroupColumnsType cols
Expand Down Expand Up @@ -195,6 +197,7 @@ data Q db table cols ord acols = (ClickhouseDb db) =>
limitQ :: Maybe Limit,
offsetQ :: Maybe Offset,
orderByQ :: Maybe (cols -> OrderBy ord),
havingQ :: Maybe (cols -> Having table),
selectModifierOverrideQ :: Maybe SelectModifier
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ asc = OrderBy Asc
desc :: forall ord. IsOrderColumns ord => ord -> OrderBy ord
desc = OrderBy Desc

having :: forall db table cols ord acols. (cols -> Having table) -> Q db table cols ord acols -> Q db table cols ord acols
having havingClause q = q {havingQ = Just havingClause}

groupBy :: forall cols gr. IsGroupColumns gr => gr -> (GroupColumnsType gr -> cols) -> (cols, GroupBy 'AGG gr)
groupBy gr mkCols = (mkCols (groupColumns gr), GroupBy gr)

Expand Down Expand Up @@ -153,6 +156,7 @@ filter_ filterClause (table, level) =
limitQ = Nothing,
offsetQ = Nothing,
orderByQ = Nothing,
havingQ = Nothing,
selectModifierOverrideQ = Nothing
}

Expand All @@ -168,6 +172,7 @@ emptyFilter (table, level) =
limitQ = Nothing,
offsetQ = Nothing,
orderByQ = Nothing,
havingQ = Nothing,
selectModifierOverrideQ = Nothing
}

Expand Down