1
Fork 0

rename Duplicates -> SetQuantifier + qeDuplicates -> qeSetQuantifier

This commit is contained in:
Jake Wheat 2013-12-19 10:34:32 +02:00
parent 2ae1ced7cc
commit 1be27eca58
4 changed files with 23 additions and 10 deletions

View file

@ -158,7 +158,7 @@ aggregate([all|distinct] args [order by orderitems])
> makeApp i (Nothing,es,Nothing) = App i es
> makeApp i (d,es,od) = AggregateApp i d es (fromMaybe [] od)
> duplicates :: P (Maybe Duplicates)
> duplicates :: P (Maybe SetQuantifier)
> duplicates = optionMaybe $ try $
> choice [All <$ keyword_ "all"
> ,Distinct <$ keyword "distinct"]

View file

@ -87,8 +87,8 @@
> scalarExpr (SpecialOp nm es) =
> name nm <+> parens (commaSep $ map scalarExpr es)
> scalarExpr (SpecialOpK (Name nm) fs as) =
> text nm <> parens (sep $ catMaybes
> scalarExpr (SpecialOpK nm fs as) =
> name nm <> parens (sep $ catMaybes
> ((fmap scalarExpr fs)
> : map (\(n,e) -> Just (text n <+> scalarExpr e)) as))

View file

@ -5,7 +5,7 @@
> ScalarExpr(..)
> ,Name(..)
> ,TypeName(..)
> ,Duplicates(..)
> ,SetQuantifier(..)
> ,SortSpec(..)
> ,Direction(..)
> ,NullsOrder(..)
@ -65,7 +65,7 @@
> -- order by, to regular function application
> | AggregateApp
> {aggName :: Name -- ^ aggregate function name
> ,aggDistinct :: Maybe Duplicates -- ^ distinct
> ,aggDistinct :: Maybe SetQuantifier -- ^ distinct
> ,aggArgs :: [ScalarExpr]-- ^ args
> ,aggOrderBy :: [SortSpec] -- ^ order by
> }
@ -192,9 +192,16 @@
> -- t'.
> data QueryExpr
> = Select
> {qeDuplicates :: Duplicates
> {qeSetQuantifier :: SetQuantifier
> ,qeSelectList :: [(Maybe Name,ScalarExpr)]
> -- ^ the column aliases and the expressions
TODO: consider breaking this up. The SQL grammar has
queryexpr = select <select list> [<table expression>]
table expression = <from> [where] [groupby] [having] ...
This would make some things a bit cleaner?
> ,qeFrom :: [TableRef]
> ,qeWhere :: Maybe ScalarExpr
> ,qeGroupBy :: [GroupingExpr]
@ -206,7 +213,7 @@
> | CombineQueryExpr
> {qe0 :: QueryExpr
> ,qeCombOp :: CombineOp
> ,qeDuplicates :: Duplicates
> ,qeSetQuantifier :: SetQuantifier
> ,qeCorresponding :: Corresponding
> ,qe1 :: QueryExpr
> }
@ -225,7 +232,7 @@ I'm not sure if this is valid syntax or not.
> -- | Helper/'default' value for query exprs to make creating query
> -- expr values a little easier.
> makeSelect :: QueryExpr
> makeSelect = Select {qeDuplicates = All
> makeSelect = Select {qeSetQuantifier = All
> ,qeSelectList = []
> ,qeFrom = []
> ,qeWhere = Nothing
@ -239,7 +246,7 @@ I'm not sure if this is valid syntax or not.
> -- | Represents the Distinct or All keywords, which can be used
> -- before a select list, in an aggregate/window function
> -- application, or in a query expression set operator.
> data Duplicates = Distinct | All deriving (Eq,Show,Read)
> data SetQuantifier = Distinct | All deriving (Eq,Show,Read)
> -- | The direction for a column in order by.
> data Direction = Asc | Desc deriving (Eq,Show,Read)

View file

@ -36,7 +36,7 @@ These are a few misc tests which don't fit anywhere else.
> ]
> where
> ms d = makeSelect
> {qeDuplicates = d
> {qeSetQuantifier = d
> ,qeSelectList = [(Nothing,Iden "a")]
> ,qeFrom = [TRSimple "t"]}
@ -64,6 +64,12 @@ These are a few misc tests which don't fit anywhere else.
> ,("select a a, b b"
> ,makeSelect {qeSelectList = [(Just "a", Iden "a")
> ,(Just "b", Iden "b")]})
> ,("select a + b * c"
> ,makeSelect {qeSelectList =
> [(Nothing,BinOp (Iden (Name "a")) (Name "+")
> (BinOp (Iden (Name "b")) (Name "*") (Iden (Name "c"))))]})
> ]
> whereClause :: TestItem