add directions to order by
This commit is contained in:
parent
2c1eedb70f
commit
1a8551825d
5 changed files with 27 additions and 10 deletions
Language/SQL/SimpleSQL
|
@ -267,10 +267,14 @@ to be.
|
|||
> having :: P (Maybe ScalarExpr)
|
||||
> having = optionMaybe (try (keyword_ "having") *> scalarExpr)
|
||||
|
||||
> orderBy :: P [ScalarExpr]
|
||||
> orderBy :: P [(ScalarExpr,Direction)]
|
||||
> orderBy = option [] (try (keyword_ "order")
|
||||
> *> keyword_ "by"
|
||||
> *> commaSep1 scalarExpr)
|
||||
> *> commaSep1 ob)
|
||||
> where
|
||||
> ob = (,) <$> scalarExpr
|
||||
> <*> option Asc (choice [Asc <$ keyword_ "asc"
|
||||
> ,Desc <$ keyword_ "desc"])
|
||||
|
||||
> queryExpr :: P QueryExpr
|
||||
> queryExpr =
|
||||
|
|
|
@ -111,10 +111,13 @@ back into SQL source text. It attempts to format the output nicely.
|
|||
> having = maybe empty
|
||||
> (\w -> sep [text "having"
|
||||
> ,nest 4 $ scalarExpr w])
|
||||
> orderBy :: [ScalarExpr] -> Doc
|
||||
> orderBy :: [(ScalarExpr,Direction)] -> Doc
|
||||
> orderBy [] = empty
|
||||
> orderBy os = sep [text "order by"
|
||||
> ,nest 4 $ commaSep $ map scalarExpr os]
|
||||
> ,nest 4 $ commaSep $ map f os]
|
||||
> where
|
||||
> f (e,Asc) = scalarExpr e
|
||||
> f (e,Desc) = scalarExpr e <+> text "desc"
|
||||
|
||||
|
||||
= utils
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
> ,TableRef(..)
|
||||
> ,JoinType(..)
|
||||
> ,JoinCondition(..)
|
||||
> ,Direction(..)
|
||||
> ) where
|
||||
|
||||
|
||||
|
@ -30,9 +31,11 @@
|
|||
> ,qeWhere :: Maybe ScalarExpr
|
||||
> ,qeGroupBy :: [ScalarExpr]
|
||||
> ,qeHaving :: Maybe ScalarExpr
|
||||
> ,qeOrderBy :: [ScalarExpr]
|
||||
> ,qeOrderBy :: [(ScalarExpr,Direction)]
|
||||
> } deriving (Eq,Show)
|
||||
|
||||
> data Direction = Asc | Desc deriving (Eq,Show)
|
||||
|
||||
> makeSelect :: QueryExpr
|
||||
> makeSelect = Select {qeSelectList = []
|
||||
> ,qeFrom = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue