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
392 changes: 212 additions & 180 deletions rel8.cabal

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/Rel8/Aggregate.hs → src-internal/Rel8/Internal/Aggregate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{-# language ScopedTypeVariables #-}
{-# language StandaloneKindSignatures #-}

module Rel8.Aggregate
module Rel8.Internal.Aggregate
( Aggregator' (Aggregator)
, Aggregator
, Aggregator1
Expand Down Expand Up @@ -35,9 +35,9 @@ import Data.Profunctor.Product
import Data.Profunctor (Profunctor, dimap)

-- rel8
import Rel8.Expr (Expr)
import Rel8.Expr.Opaleye (toPrimExpr, toColumn)
import Rel8.Aggregate.Fold (Fallback (Empty, Fallback), Fold (Full, Semi))
import Rel8.Internal.Expr (Expr)
import Rel8.Internal.Expr.Opaleye (toPrimExpr, toColumn)
import Rel8.Internal.Aggregate.Fold (Fallback (Empty, Fallback), Fold (Full, Semi))

-- semigroupoids
import Data.Functor.Apply (Apply, liftF2)
Expand All @@ -47,11 +47,11 @@ import Data.Functor.Apply (Apply, liftF2)
-- 'Aggregator' and 'Aggregator1' are special cases. 'Aggregator''s are
-- comprised of aggregation functions and/or @GROUP BY@ clauses.
--
-- Aggregation functions operating on individual 'Rel8.Expr's such as
-- 'Rel8.sum' can be combined into 'Aggregator's operating on larger types
-- Aggregation functions operating on individual 'Rel8.Internal.Expr's such as
-- 'Rel8.Internal.sum' can be combined into 'Aggregator's operating on larger types
-- using the 'Applicative', 'Profunctor' and 'ProductProfunctor' interfaces.
-- Working with 'Profunctor's can sometimes be awkward so for every 'Rel8.sum'
-- we also provide a 'Rel8.sumOn' which bundles an 'Data.Profunctor.lmap'. For
-- Working with 'Profunctor's can sometimes be awkward so for every 'Rel8.Internal.sum'
-- we also provide a 'Rel8.Internal.sumOn' which bundles an 'Data.Profunctor.lmap'. For
-- complex aggregations, we recommend using these functions along with
-- @ApplicativeDo@, @BlockArguments@, @OverloadedRecordDot@ and
-- @RecordWildCards@:
Expand Down Expand Up @@ -140,12 +140,12 @@ instance Applicative (Aggregator' fold i) where
liftA2 = liftF2


-- | An 'Aggregator' takes a 'Rel8.Query' producing a collection of rows of
-- type @a@ and transforms it into a 'Rel8.Query' producing a single row of
-- type @b@. If the given 'Rel8.Query' produces an empty collection of rows,
-- then the single row in the resulting 'Rel8.Query' contains the identity
-- | An 'Aggregator' takes a 'Rel8.Internal.Query' producing a collection of rows of
-- type @a@ and transforms it into a 'Rel8.Internal.Query' producing a single row of
-- type @b@. If the given 'Rel8.Internal.Query' produces an empty collection of rows,
-- then the single row in the resulting 'Rel8.Internal.Query' contains the identity
-- values of the aggregation functions comprising the 'Aggregator' (i.e.,
-- @0@ for 'Rel8.sum', 'Rel8.false' for 'Rel8.or', etc.).
-- @0@ for 'Rel8.Internal.sum', 'Rel8.false' for 'Rel8.or', etc.).
--
-- 'Aggregator' is a special form of 'Aggregator'' parameterised by 'Full'.
type Aggregator :: Type -> Type -> Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# language LambdaCase #-}
{-# language StandaloneKindSignatures #-}

module Rel8.Aggregate.Fold
module Rel8.Internal.Aggregate.Fold
( Fallback (Empty, Fallback)
, Fold (Semi, Full)
)
Expand All @@ -20,7 +20,7 @@ import Data.Functor.Apply (Apply, liftF2)

-- | 'Fold' is a kind that parameterises aggregations. Aggregations
-- parameterised by 'Semi' are analogous to 'Data.Semigroup.Foldable.foldMap1'
-- (i.e, they can only produce results on a non-empty 'Rel8.Query') whereas
-- (i.e, they can only produce results on a non-empty 'Rel8.Internal.Query') whereas
-- aggregations parameterised by 'Full' are analagous to 'foldMap' (given a
-- non-empty) query, they return the identity values of the aggregation
-- functions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# language FlexibleContexts #-}
{-# language MonoLocalBinds #-}

module Rel8.Aggregate.Function (
module Rel8.Internal.Aggregate.Function (
aggregateFunction,
rawAggregateFunction,
) where
Expand All @@ -14,20 +14,20 @@ 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)
import Rel8.Internal.Aggregate (Aggregator1, unsafeMakeAggregator)
import Rel8.Internal.Aggregate.Fold (Fallback (Empty))
import Rel8.Internal.Expr (Expr)
import Rel8.Internal.Expr.Opaleye (castExpr, fromColumn, fromPrimExpr)
import Rel8.Internal.Schema.Null (Sql)
import Rel8.Internal.Schema.QualifiedName (QualifiedName, showQualifiedName)
import Rel8.Internal.Table (Table)
import Rel8.Internal.Table.Opaleye (unpackspec)
import Rel8.Internal.Type (DBType)


-- | 'aggregateFunction' allows the use use of custom aggregation functions
-- or PostgreSQL aggregation functions which are not otherwise supported by
-- Rel8.
-- Rel8.Internal.
aggregateFunction ::
(Table Expr i, Sql DBType a) =>
QualifiedName ->
Expand Down
21 changes: 21 additions & 0 deletions src-internal/Rel8/Internal/Aggregate/Range.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{-# LANGUAGE OverloadedStrings #-}

module Rel8.Internal.Aggregate.Range (
rangeAgg,
) where

-- base
import Prelude

-- rel8
import Rel8.Internal.Aggregate (Aggregator', toAggregator)
import Rel8.Internal.Aggregate.Function (aggregateFunction)
import Rel8.Internal.Data.Range (Multirange, Range)
import Rel8.Internal.Expr (Expr)
import Rel8.Internal.Type.Range (DBRange)


rangeAgg ::
DBRange a =>
Aggregator' fold (Expr (Range a)) (Expr (Multirange a))
rangeAgg = toAggregator mempty $ aggregateFunction "range_agg"
8 changes: 4 additions & 4 deletions src/Rel8/Column.hs → src-internal/Rel8/Internal/Column.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilies #-}

module Rel8.Column
module Rel8.Internal.Column
( Column
, TColumn
)
Expand All @@ -13,9 +13,9 @@ import Data.Kind ( Type )
import Prelude ()

-- rel8
import Rel8.FCF ( Eval, Exp )
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Internal.FCF ( Eval, Exp )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )


-- | This type family is used to specify columns in 'Rel8able's. In @Column f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilies #-}

module Rel8.Column.ADT
module Rel8.Internal.Column.ADT
( HADT
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude ()

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.ADT ( ADT )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.ADT ( ADT )


type HADT :: K.Context -> K.Rel8able -> Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilyDependencies #-}

module Rel8.Column.Either
module Rel8.Internal.Column.Either
( HEither
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.Either ( EitherTable )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.Either ( EitherTable )


-- | Nest an 'Either' value within a 'Rel8able'. @HEither f a b@ will produce a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilies #-}

module Rel8.Column.Lift
module Rel8.Internal.Column.Lift
( Lift
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude ()

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.HKD ( HKD )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.HKD ( HKD )


type Lift :: K.Context -> Type -> Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilyDependencies #-}

module Rel8.Column.List
module Rel8.Internal.Column.List
( HList
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude ()

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.List ( ListTable )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.List ( ListTable )


-- | Nest a list within a 'Rel8able'. @HList f a@ will produce a 'ListTable'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilyDependencies #-}

module Rel8.Column.Maybe
module Rel8.Internal.Column.Maybe
( HMaybe
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.Maybe ( MaybeTable )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.Maybe ( MaybeTable )


-- | Nest a 'Maybe' value within a 'Rel8able'. @HMaybe f a@ will produce a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilyDependencies #-}

module Rel8.Column.NonEmpty
module Rel8.Internal.Column.NonEmpty
( HNonEmpty
)
where
Expand All @@ -13,9 +13,9 @@ import Data.List.NonEmpty ( NonEmpty )
import Prelude ()

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.NonEmpty ( NonEmptyTable )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.NonEmpty ( NonEmptyTable )


-- | Nest a 'NonEmpty' list within a 'Rel8able'. @HNonEmpty f a@ will produce a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilyDependencies #-}

module Rel8.Column.Null
module Rel8.Internal.Column.Null
( HNull
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.Null ( NullTable )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.Null ( NullTable )


-- | Nest a 'Null' value within a 'Rel8able'. @HNull f a@ will produce a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilyDependencies #-}

module Rel8.Column.These
module Rel8.Internal.Column.These
( HThese
)
where
Expand All @@ -12,9 +12,9 @@ import Data.Kind ( Type )
import Prelude ()

-- rel8
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )
import Rel8.Table.These ( TheseTable )
import qualified Rel8.Internal.Schema.Kind as K
import Rel8.Internal.Schema.Result ( Result )
import Rel8.Internal.Table.These ( TheseTable )

-- these
import Data.These ( These )
Expand Down
32 changes: 16 additions & 16 deletions src/Rel8/Data/Range.hs → src-internal/Rel8/Internal/Data/Range.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Rel8.Data.Range (
module Rel8.Internal.Data.Range (
Bound (Incl, Excl, Inf),
Range (Empty, Range),
quoteRange,
Expand Down Expand Up @@ -46,25 +46,25 @@ import PostgreSQL.Binary.Range (Bound (Incl, Excl, Inf), Range (Empty, Range))
import qualified PostgreSQL.Binary.Range as PostgreSQL

-- rel8
import Rel8.Schema.QualifiedName (QualifiedName, showQualifiedName)
import Rel8.Type (DBType, typeInformation)
import Rel8.Type.Builder.Fold (interfoldMap)
import Rel8.Type.Decoder (Decoder (Decoder))
import qualified Rel8.Type.Decoder
import Rel8.Type.Encoder (Encoder (Encoder))
import qualified Rel8.Type.Encoder
import Rel8.Type.Eq (DBEq)
import Rel8.Type.Information (TypeInformation (TypeInformation))
import qualified Rel8.Type.Information
import Rel8.Type.Name (TypeName (TypeName))
import qualified Rel8.Type.Name
import Rel8.Type.Ord (DBOrd)
import Rel8.Type.Range (
import Rel8.Internal.Schema.QualifiedName (QualifiedName, showQualifiedName)
import Rel8.Internal.Type (DBType, typeInformation)
import Rel8.Internal.Type.Builder.Fold (interfoldMap)
import Rel8.Internal.Type.Decoder (Decoder (Decoder))
import qualified Rel8.Internal.Type.Decoder
import Rel8.Internal.Type.Encoder (Encoder (Encoder))
import qualified Rel8.Internal.Type.Encoder
import Rel8.Internal.Type.Eq (DBEq)
import Rel8.Internal.Type.Information (TypeInformation (TypeInformation))
import qualified Rel8.Internal.Type.Information
import Rel8.Internal.Type.Name (TypeName (TypeName))
import qualified Rel8.Internal.Type.Name
import Rel8.Internal.Type.Ord (DBOrd)
import Rel8.Internal.Type.Range (
DBRange,
rangeTypeName, rangeEncoder, rangeDecoder,
multirangeTypeName, multirangeEncoder, multirangeDecoder,
)
import Rel8.Type.Parser (parse)
import Rel8.Internal.Type.Parser (parse)


newtype Multirange a = Multirange (PostgreSQL.Multirange a)
Expand Down
Loading
Loading