module Database.Relational.Query.Internal.Sub
( SubQuery (..), UntypedProjection, ProjectionUnit (..)
, SetOp (..), BinOp (..), Qualifier (..), Qualified (..)
, NodeAttr (..), ProductTree (..), Node (..)
, JoinProduct, QueryProductTree
, ProductTreeBuilder, ProductBuilder
, Projection, untypeProjection, typedProjection
, QueryRestriction
) where
import Prelude hiding (and, product)
import Data.Array (Array)
import Data.DList (DList)
import Database.Relational.Query.Context (Flat, Aggregated)
import Database.Relational.Query.Component
(ColumnSQL, Config, Duplication (..),
AggregateElem, OrderingTerms)
import qualified Database.Relational.Query.Table as Table
data SetOp = Union | Except | Intersect deriving Show
newtype BinOp = BinOp (SetOp, Duplication) deriving Show
data SubQuery = Table Table.Untyped
| Flat Config
UntypedProjection Duplication JoinProduct (QueryRestriction Flat)
OrderingTerms
| Aggregated Config
UntypedProjection Duplication JoinProduct (QueryRestriction Flat)
[AggregateElem] (QueryRestriction Aggregated) OrderingTerms
| Bin BinOp SubQuery SubQuery
deriving Show
newtype Qualifier = Qualifier Int deriving Show
data Qualified a = Qualified a Qualifier deriving Show
instance Functor Qualified where
fmap f (Qualified a i) = Qualified (f a) i
data ProjectionUnit = Columns (Array Int ColumnSQL)
| Normalized (Qualified Int)
| Scalar SubQuery
deriving Show
type UntypedProjection = [ProjectionUnit]
data NodeAttr = Just' | Maybe deriving Show
type QS = Qualified SubQuery
type QueryRestrictionBuilder = DList (Projection Flat (Maybe Bool))
data ProductTree rs
= Leaf QS
| Join !(Node rs) !(Node rs) !rs
deriving (Show, Functor)
data Node rs = Node !NodeAttr !(ProductTree rs) deriving (Show, Functor)
type QueryProductTree = ProductTree (QueryRestriction Flat)
type ProductTreeBuilder = ProductTree QueryRestrictionBuilder
type ProductBuilder = Node QueryRestrictionBuilder
type JoinProduct = Maybe QueryProductTree
newtype Projection c t =
Projection
{ untypeProjection :: UntypedProjection } deriving Show
typedProjection :: UntypedProjection -> Projection c t
typedProjection = Projection
type QueryRestriction c = [Projection c (Maybe Bool)]