mirror of
https://github.com/circuithub/rel8.git
synced 2024-08-16 19:30:26 +03:00
Add ability to use custom aggregation functions with aggregateFunction
(#283)
This commit is contained in:
parent
91e7a1bfab
commit
b5789a692e
@ -0,0 +1,3 @@
|
|||||||
|
### Added
|
||||||
|
|
||||||
|
- `aggregationFunction`, which allows custom aggregation functions to be used.
|
@ -70,6 +70,7 @@ library
|
|||||||
other-modules:
|
other-modules:
|
||||||
Rel8.Aggregate
|
Rel8.Aggregate
|
||||||
Rel8.Aggregate.Fold
|
Rel8.Aggregate.Fold
|
||||||
|
Rel8.Aggregate.Function
|
||||||
|
|
||||||
Rel8.Column
|
Rel8.Column
|
||||||
Rel8.Column.ADT
|
Rel8.Column.ADT
|
||||||
|
@ -284,6 +284,7 @@ module Rel8
|
|||||||
, countWhere, countWhereOn
|
, countWhere, countWhereOn
|
||||||
, and, andOn
|
, and, andOn
|
||||||
, or, orOn
|
, or, orOn
|
||||||
|
, aggregateFunction
|
||||||
|
|
||||||
, mode, modeOn
|
, mode, modeOn
|
||||||
, percentile, percentileOn
|
, percentile, percentileOn
|
||||||
@ -383,6 +384,7 @@ import Prelude ()
|
|||||||
-- rel8
|
-- rel8
|
||||||
import Rel8.Aggregate
|
import Rel8.Aggregate
|
||||||
import Rel8.Aggregate.Fold
|
import Rel8.Aggregate.Fold
|
||||||
|
import Rel8.Aggregate.Function
|
||||||
import Rel8.Column
|
import Rel8.Column
|
||||||
import Rel8.Column.ADT
|
import Rel8.Column.ADT
|
||||||
import Rel8.Column.Either
|
import Rel8.Column.Either
|
||||||
|
40
src/Rel8/Aggregate/Function.hs
Normal file
40
src/Rel8/Aggregate/Function.hs
Normal file
@ -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)))
|
Loading…
Reference in New Issue
Block a user