module Database.Relational.Query.Internal.Sub
( SubQuery (..), UntypedProjection, ProjectionUnit (..)
, SetOp (..), BinOp (..), Qualifier (..), Qualified (..)
, NodeAttr (..), ProductTree (..), Node (..)
, JoinProduct, QueryProduct, QueryProductNode
, Projection, untypeProjection, typedProjection
, QueryRestriction
) where
import Prelude hiding (and, product)
import Data.Array (Array)
import Data.DList (DList)
import qualified Database.Relational.Query.Context as Context
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 Context.Flat)
OrderingTerms
| Aggregated Config
UntypedProjection Duplication JoinProduct (QueryRestriction Context.Flat)
[AggregateElem] (QueryRestriction Context.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
data ProductTree q = Leaf q
| Join !(Node q) !(Node q) !(DList (Projection Context.Flat (Maybe Bool)))
deriving Show
data Node q = Node !NodeAttr !(ProductTree q) deriving Show
type QueryProduct = ProductTree (Qualified SubQuery)
type QueryProductNode = Node (Qualified SubQuery)
type JoinProduct = Maybe QueryProduct
newtype Projection c t =
Projection
{ untypeProjection :: UntypedProjection } deriving Show
typedProjection :: UntypedProjection -> Projection c t
typedProjection = Projection
type QueryRestriction c = [Projection c (Maybe Bool)]