1
Fork 0

add syntax for new grouping expressions

This commit is contained in:
Jake Wheat 2013-12-17 19:17:03 +02:00
parent 7d094182b7
commit b703e04af3
9 changed files with 266 additions and 28 deletions
Language/SQL/SimpleSQL

View file

@ -598,10 +598,10 @@ where, having, limit, offset).
> swhere :: P ScalarExpr
> swhere = keywordScalarExpr "where"
> sgroupBy :: P [ScalarExpr]
> sgroupBy :: P [GroupingExpr]
> sgroupBy = try (keyword_ "group")
> *> keyword_ "by"
> *> commaSep1 scalarExpr
> *> commaSep1 (SimpleGroup <$> scalarExpr)
> having :: P ScalarExpr
> having = keywordScalarExpr "having"

View file

@ -255,10 +255,16 @@
> (\e -> sep [text k
> ,nest (length k + 1) $ scalarExpr e])
> grpBy :: [ScalarExpr] -> Doc
> grpBy :: [GroupingExpr] -> Doc
> grpBy [] = empty
> grpBy gs = sep [text "group by"
> ,nest 9 $ commaSep $ map scalarExpr gs]
> ,nest 9 $ commaSep $ map ge gs]
> where
> ge (SimpleGroup e) = scalarExpr e
> ge (GroupingParens g) = parens (commaSep $ map ge g)
> ge (Cube es) = text "cube" <> parens (commaSep $ map ge es)
> ge (Rollup es) = text "rollup" <> parens (commaSep $ map ge es)
> ge (GroupingSets es) = text "grouping sets" <> parens (commaSep $ map ge es)
> orderBy :: [OrderField] -> Doc
> orderBy [] = empty

View file

@ -20,6 +20,7 @@
> ,CombineOp(..)
> ,Corresponding(..)
> ,Alias(..)
> ,GroupingExpr(..)
> -- ** From
> ,TableRef(..)
> ,JoinType(..)
@ -189,7 +190,7 @@
> -- ^ the column aliases and the expressions
> ,qeFrom :: [TableRef]
> ,qeWhere :: Maybe ScalarExpr
> ,qeGroupBy :: [ScalarExpr]
> ,qeGroupBy :: [GroupingExpr]
> ,qeHaving :: Maybe ScalarExpr
> ,qeOrderBy :: [OrderField]
> ,qeOffset :: Maybe ScalarExpr
@ -240,6 +241,14 @@ I'm not sure if this is valid syntax or not.
> -- | Corresponding, an option for the set operators
> data Corresponding = Corresponding | Respectively deriving (Eq,Show,Read)
> data GroupingExpr
> = GroupingParens [GroupingExpr]
> | Cube [GroupingExpr]
> | Rollup [GroupingExpr]
> | GroupingSets [GroupingExpr]
> | SimpleGroup ScalarExpr
> deriving (Eq,Show,Read)
> -- | Represents a entry in the csv of tables in the from clause.
> data TableRef = -- | from t
> TRSimple Name