Copyright | 2017 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | unknown |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Database.Relational.SqlSyntax
Contents
- The SubQuery
- Set operations
- Qualifiers for nested query
- Ordering types
- Aggregating types
- Product tree type
- Case
- Column, Tuple, Record and Projection
- Predicate to restrict Query result
- Sub-query
- Qualified Sub-query
- Sub-query columns
- Tuple and Record
- Query restriction
- Aggregation
- Ordering
- Update and Insert assignments
Description
This module is integrated module of sql-syntax.
Synopsis
- data SubQuery
- = Table Untyped
- | Flat Config Tuple Duplication JoinProduct [Predicate Flat] [OrderingTerm]
- | Aggregated Config Tuple Duplication JoinProduct [Predicate Flat] [AggregateElem] [Predicate Aggregated] [OrderingTerm]
- | Bin BinOp SubQuery SubQuery
- data Duplication
- data SetOp
- newtype BinOp = BinOp (SetOp, Duplication)
- newtype Qualifier = Qualifier Int
- data Qualified a = Qualified Qualifier a
- qualifier :: Qualified a -> Qualifier
- unQualify :: Qualified a -> a
- qualify :: Qualifier -> a -> Qualified a
- data Order
- data Nulls
- type OrderColumn = Column
- type OrderingTerm = ((Order, Maybe Nulls), OrderColumn)
- type AggregateColumnRef = Column
- newtype AggregateBitKey = AggregateBitKey [AggregateColumnRef]
- newtype AggregateSet = AggregateSet [AggregateElem]
- data AggregateElem
- newtype AggregateKey a = AggregateKey (a, AggregateElem)
- data NodeAttr
- data ProductTree rs
- data Node rs = Node !NodeAttr !(ProductTree rs)
- nodeAttr :: Node rs -> NodeAttr
- nodeTree :: Node rs -> ProductTree rs
- type JoinProduct = Maybe (ProductTree [Predicate Flat])
- data CaseClause
- data WhenClauses = WhenClauses [(Tuple, Tuple)] Tuple
- data Column
- type Tuple = [Column]
- tupleWidth :: Tuple -> Int
- data Record c t
- untypeRecord :: Record c t -> Tuple
- record :: Tuple -> Record c t
- type PI c a b = Record c a -> Record c b
- recordWidth :: Record c r -> Int
- typeFromRawColumns :: [StringSQL] -> Record c r
- typeFromScalarSubQuery :: SubQuery -> Record c t
- type Predicate c = Record c (Maybe Bool)
- growProduct :: Maybe (Node (DList (Predicate Flat))) -> (NodeAttr, (Bool, Qualified SubQuery)) -> Node (DList (Predicate Flat))
- restrictProduct :: Node (DList (Predicate Flat)) -> Predicate Flat -> Node (DList (Predicate Flat))
- aggregateColumnRef :: AggregateColumnRef -> AggregateElem
- aggregatePowerKey :: [AggregateColumnRef] -> AggregateBitKey
- aggregateGroupingSet :: [AggregateElem] -> AggregateSet
- aggregateRollup :: [AggregateBitKey] -> AggregateElem
- aggregateCube :: [AggregateBitKey] -> AggregateElem
- aggregateSets :: [AggregateSet] -> AggregateElem
- aggregateKeyRecord :: AggregateKey a -> a
- aggregateKeyElement :: AggregateKey a -> AggregateElem
- unsafeAggregateKey :: (a, AggregateElem) -> AggregateKey a
- flatSubQuery :: Config -> Tuple -> Duplication -> JoinProduct -> [Predicate Flat] -> [OrderingTerm] -> SubQuery
- aggregatedSubQuery :: Config -> Tuple -> Duplication -> JoinProduct -> [Predicate Flat] -> [AggregateElem] -> [Predicate Aggregated] -> [OrderingTerm] -> SubQuery
- union :: Duplication -> SubQuery -> SubQuery -> SubQuery
- except :: Duplication -> SubQuery -> SubQuery -> SubQuery
- intersect :: Duplication -> SubQuery -> SubQuery -> SubQuery
- caseSearch :: [(Predicate c, Record c a)] -> Record c a -> Record c a
- case' :: Record c a -> [(Record c a, Record c b)] -> Record c b -> Record c b
- showSQL :: SubQuery -> StringSQL
- toSQL :: SubQuery -> String
- unitSQL :: SubQuery -> String
- width :: SubQuery -> Int
- queryWidth :: Qualified SubQuery -> Int
- corrSubQueryTerm :: Bool -> Qualified SubQuery -> StringSQL
- column :: Qualified SubQuery -> Int -> StringSQL
- tupleFromJoinedSubQuery :: Qualified SubQuery -> Tuple
- recordRawColumns :: Record c r -> [StringSQL]
- composeWhere :: [Predicate Flat] -> StringSQL
- composeHaving :: [Predicate Aggregated] -> StringSQL
- composeGroupBy :: [AggregateElem] -> StringSQL
- composePartitionBy :: [AggregateColumnRef] -> StringSQL
- composeOrderBy :: [OrderingTerm] -> StringSQL
- type AssignColumn = StringSQL
- type AssignTerm = StringSQL
- type Assignment = (AssignColumn, AssignTerm)
- composeSets :: [Assignment] -> StringSQL
- composeChunkValues :: Int -> [AssignTerm] -> Keyword
- composeChunkValuesWithColumns :: Int -> [Assignment] -> StringSQL
- composeValuesListWithColumns :: [[Assignment]] -> StringSQL
The SubQuery
Sub-query type
Constructors
Set operations
data Duplication Source #
Result record duplication attribute
Instances
Show Duplication Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods showsPrec :: Int -> Duplication -> ShowS # show :: Duplication -> String # showList :: [Duplication] -> ShowS # |
Set operators
Set binary operators
Constructors
BinOp (SetOp, Duplication) |
Qualifiers for nested query
Qualifier type.
Qualified query.
Instances
Foldable Qualified Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods fold :: Monoid m => Qualified m -> m # foldMap :: Monoid m => (a -> m) -> Qualified a -> m # foldMap' :: Monoid m => (a -> m) -> Qualified a -> m # foldr :: (a -> b -> b) -> b -> Qualified a -> b # foldr' :: (a -> b -> b) -> b -> Qualified a -> b # foldl :: (b -> a -> b) -> b -> Qualified a -> b # foldl' :: (b -> a -> b) -> b -> Qualified a -> b # foldr1 :: (a -> a -> a) -> Qualified a -> a # foldl1 :: (a -> a -> a) -> Qualified a -> a # toList :: Qualified a -> [a] # length :: Qualified a -> Int # elem :: Eq a => a -> Qualified a -> Bool # maximum :: Ord a => Qualified a -> a # minimum :: Ord a => Qualified a -> a # | |
Traversable Qualified Source # | |
Defined in Database.Relational.SqlSyntax.Types | |
Functor Qualified Source # | |
Show a => Show (Qualified a) Source # | |
Ordering types
Order direction. Ascendant or Descendant.
Order of null.
Constructors
NullsFirst | |
NullsLast |
type OrderColumn = Column Source #
Type for order-by column
type OrderingTerm = ((Order, Maybe Nulls), OrderColumn) Source #
Type for order-by term
Aggregating types
type AggregateColumnRef = Column Source #
Type for group-by term
newtype AggregateBitKey Source #
Type for group key.
Constructors
AggregateBitKey [AggregateColumnRef] |
Instances
Show AggregateBitKey Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods showsPrec :: Int -> AggregateBitKey -> ShowS # show :: AggregateBitKey -> String # showList :: [AggregateBitKey] -> ShowS # |
newtype AggregateSet Source #
Type for grouping set
Constructors
AggregateSet [AggregateElem] |
Instances
Show AggregateSet Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods showsPrec :: Int -> AggregateSet -> ShowS # show :: AggregateSet -> String # showList :: [AggregateSet] -> ShowS # |
data AggregateElem Source #
Type for group-by tree
Constructors
ColumnRef AggregateColumnRef | |
Rollup [AggregateBitKey] | |
Cube [AggregateBitKey] | |
GroupingSets [AggregateSet] |
Instances
newtype AggregateKey a Source #
Typeful aggregate element.
Constructors
AggregateKey (a, AggregateElem) |
Product tree type
node attribute for product.
data ProductTree rs Source #
Product tree type. Product tree is constructed by left node and right node.
Instances
Functor ProductTree Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods fmap :: (a -> b) -> ProductTree a -> ProductTree b # (<$) :: a -> ProductTree b -> ProductTree a # | |
Show rs => Show (ProductTree rs) Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods showsPrec :: Int -> ProductTree rs -> ShowS # show :: ProductTree rs -> String # showList :: [ProductTree rs] -> ShowS # |
Product node. node attribute and product tree.
Constructors
Node !NodeAttr !(ProductTree rs) |
nodeTree :: Node rs -> ProductTree rs Source #
Get tree from node.
type JoinProduct = Maybe (ProductTree [Predicate Flat]) Source #
Type for join product of query.
Case
data CaseClause Source #
case clause
Constructors
CaseSearch WhenClauses | |
CaseSimple Tuple WhenClauses |
Instances
Show CaseClause Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods showsPrec :: Int -> CaseClause -> ShowS # show :: CaseClause -> String # showList :: [CaseClause] -> ShowS # |
data WhenClauses Source #
when clauses
Constructors
WhenClauses [(Tuple, Tuple)] Tuple |
Instances
Show WhenClauses Source # | |
Defined in Database.Relational.SqlSyntax.Types Methods showsPrec :: Int -> WhenClauses -> ShowS # show :: WhenClauses -> String # showList :: [WhenClauses] -> ShowS # |
Column, Tuple, Record and Projection
Projected column structure unit with single column width
Constructors
RawColumn StringSQL | used in immediate value or unsafe operations |
SubQueryRef (Qualified Int) | normalized sub-query reference Tn with Int index |
Scalar SubQuery | scalar sub-query |
Case CaseClause Int | nth column of case clause |
Instances
Show Column Source # | |
Monad m => MonadPartition c (PartitioningSetT c m) Source # | Partition clause instance |
Defined in Database.Relational.Monad.Trans.Aggregating Methods partitionBy :: Record c r -> PartitioningSetT c m () Source # |
Phantom typed record. Projected into Haskell record type t
.
Instances
(PersistableWidth a, HasProjection l a b) => IsLabel l (PI c a b) Source # | Derive |
Defined in Database.Relational.OverloadedProjection | |
ProductIsoApplicative (Record c) Source # | Compose |
Defined in Database.Relational.Record | |
ProductIsoFunctor (Record c) Source # | Map |
Defined in Database.Relational.Record Methods (|$|) :: ProductConstructor (a -> b) => (a -> b) -> Record c a -> Record c b # | |
ProjectableMaybe (Record c) Source # | |
ProductIsoEmpty (Record c) () Source # | |
Show (Record c t) Source # | |
TableDerivable r => Show (Record Flat r -> Assign r (PlaceHolders p)) Source # | Show Set clause and WHERE clause. |
TableDerivable r => Show (Record Flat r -> Restrict (PlaceHolders p)) Source # | Show WHERE clause. |
untypeRecord :: Record c t -> Tuple Source #
Discard record type
Unsafely generate Record
from SQL string list.
typeFromScalarSubQuery :: SubQuery -> Record c t Source #
Unsafely generate Record
from scalar sub-query.
Predicate to restrict Query result
Arguments
:: Maybe (Node (DList (Predicate Flat))) | Current tree |
-> (NodeAttr, (Bool, Qualified SubQuery)) | New leaf to push into right |
-> Node (DList (Predicate Flat)) | Result node |
Push new leaf node into product right term.
Arguments
:: Node (DList (Predicate Flat)) | Target node which has product to restrict |
-> Predicate Flat | Restriction to add |
-> Node (DList (Predicate Flat)) | Result node |
Add restriction into top product of product tree node.
aggregateColumnRef :: AggregateColumnRef -> AggregateElem Source #
Single term aggregation element.
aggregatePowerKey :: [AggregateColumnRef] -> AggregateBitKey Source #
Key of aggregation power set.
aggregateGroupingSet :: [AggregateElem] -> AggregateSet Source #
Single grouping set.
aggregateRollup :: [AggregateBitKey] -> AggregateElem Source #
Rollup aggregation element.
aggregateCube :: [AggregateBitKey] -> AggregateElem Source #
Cube aggregation element.
aggregateSets :: [AggregateSet] -> AggregateElem Source #
Grouping sets aggregation.
aggregateKeyRecord :: AggregateKey a -> a Source #
Extract typed record from AggregateKey
.
aggregateKeyElement :: AggregateKey a -> AggregateElem Source #
Extract untyped term from AggregateKey
.
unsafeAggregateKey :: (a, AggregateElem) -> AggregateKey a Source #
Unsafely bind typed-record and untyped-term into AggregateKey
.
flatSubQuery :: Config -> Tuple -> Duplication -> JoinProduct -> [Predicate Flat] -> [OrderingTerm] -> SubQuery Source #
Unsafely generate flat SubQuery
from untyped components.
aggregatedSubQuery :: Config -> Tuple -> Duplication -> JoinProduct -> [Predicate Flat] -> [AggregateElem] -> [Predicate Aggregated] -> [OrderingTerm] -> SubQuery Source #
Unsafely generate aggregated SubQuery
from untyped components.
except :: Duplication -> SubQuery -> SubQuery -> SubQuery Source #
Except binary operator on SubQuery
intersect :: Duplication -> SubQuery -> SubQuery -> SubQuery Source #
Intersect binary operator on SubQuery
Arguments
:: [(Predicate c, Record c a)] | Each when clauses |
-> Record c a | Else result record |
-> Record c a | Result record |
Search case operator correnponding SQL search CASE. Like, CASE WHEN p0 THEN a WHEN p1 THEN b ... ELSE c END
Arguments
:: Record c a | Record value to match |
-> [(Record c a, Record c b)] | Each when clauses |
-> Record c b | Else result record |
-> Record c b | Result record |
Simple case operator correnponding SQL simple CASE. Like, CASE x WHEN v THEN a WHEN w THEN b ... ELSE c END
Sub-query
Qualified Sub-query
Sub-query columns
Tuple and Record
Get column SQL string list of record.
Query restriction
composeHaving :: [Predicate Aggregated] -> StringSQL Source #
Compose HAVING clause from QueryRestriction
.
Aggregation
composeGroupBy :: [AggregateElem] -> StringSQL Source #
Compose GROUP BY clause from AggregateElem list.
composePartitionBy :: [AggregateColumnRef] -> StringSQL Source #
Compose PARTITION BY clause from AggregateColumnRef list.
Ordering
composeOrderBy :: [OrderingTerm] -> StringSQL Source #
Compose ORDER BY clause from OrderingTerms
Update and Insert assignments
type AssignColumn = StringSQL Source #
Column SQL String of assignment
type AssignTerm = StringSQL Source #
Value SQL String of assignment
type Assignment = (AssignColumn, AssignTerm) Source #
Assignment pair
composeSets :: [Assignment] -> StringSQL Source #
Compose SET clause from [Assignment
].
Arguments
:: Int | record count per chunk |
-> [AssignTerm] | value expression list |
-> Keyword |
Compose VALUES clause from a row of value expressions.
composeChunkValuesWithColumns Source #
Arguments
:: Int | record count per chunk |
-> [Assignment] | |
-> StringSQL |
Compose columns row and VALUES clause from a row of value expressions.
composeValuesListWithColumns :: [[Assignment]] -> StringSQL Source #
Compose columns row and VALUES clause from rows list of value expressions.