-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to use custom aggregation functions with
aggregateFunction
- Loading branch information
1 parent
a94dd9a
commit 068517e
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelog.d/20231009_170238_shane.obrien_aggregateFunction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Added | ||
|
||
- `aggregationFunction`, which allows custom aggregation functions to be used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# language FlexibleContexts #-} | ||
{-# language MonoLocalBinds #-} | ||
|
||
module Rel8.Aggregate.Function ( | ||
aggregateFunction, | ||
) where | ||
|
||
-- base | ||
import Prelude | ||
|
||
-- opaleye | ||
import qualified Opaleye.Internal.Aggregate as Opaleye | ||
import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye | ||
|
||
-- rel8 | ||
import Rel8.Aggregate (Aggregator1, unsafeMakeAggregator) | ||
import Rel8.Aggregate.Fold (Fallback (Empty)) | ||
import Rel8.Expr (Expr) | ||
import Rel8.Expr.Opaleye (castExpr, fromColumn, fromPrimExpr) | ||
import Rel8.Schema.Null (Sql) | ||
import Rel8.Schema.QualifiedName (QualifiedName, showQualifiedName) | ||
import Rel8.Table (Table) | ||
import Rel8.Table.Opaleye (unpackspec) | ||
import Rel8.Type (DBType) | ||
|
||
|
||
-- | 'aggregateFunction' allows the use use of custom aggregation functions | ||
-- or PostgreSQL aggregation functions which are not otherwise supported by | ||
-- Rel8. | ||
aggregateFunction :: | ||
(Table Expr i, Sql DBType a) => | ||
QualifiedName -> | ||
Aggregator1 i (Expr a) | ||
aggregateFunction name = | ||
unsafeMakeAggregator | ||
id | ||
(castExpr . fromPrimExpr . fromColumn) | ||
Empty | ||
(Opaleye.makeAggrExplicit unpackspec | ||
(Opaleye.AggrOther (showQualifiedName name))) |