work on haddock and a few renames
This commit is contained in:
parent
c28db4d470
commit
b001276337
|
@ -24,12 +24,14 @@ The public api functions.
|
||||||
> -> Either ParseError QueryExpr
|
> -> Either ParseError QueryExpr
|
||||||
> parseQueryExpr = wrapParse topLevelQueryExpr
|
> parseQueryExpr = wrapParse topLevelQueryExpr
|
||||||
|
|
||||||
|
> -- | Parses a list of query exprs, with semi colons between them. The final semicolon is optional.
|
||||||
> parseQueryExprs :: FilePath -- ^ filename to use in errors
|
> parseQueryExprs :: FilePath -- ^ filename to use in errors
|
||||||
> -> Maybe (Int,Int) -- ^ line number and column number to use in errors
|
> -> Maybe (Int,Int) -- ^ line number and column number to use in errors
|
||||||
> -> String -- ^ the sql source to parse
|
> -> String -- ^ the sql source to parse
|
||||||
> -> Either ParseError [QueryExpr]
|
> -> Either ParseError [QueryExpr]
|
||||||
> parseQueryExprs = wrapParse queryExprs
|
> parseQueryExprs = wrapParse queryExprs
|
||||||
|
|
||||||
|
> -- | Parses a scalar expression.
|
||||||
> parseScalarExpr :: FilePath -- ^ filename to use in errors
|
> parseScalarExpr :: FilePath -- ^ filename to use in errors
|
||||||
> -> Maybe (Int,Int) -- ^ line number and column number to use in errors
|
> -> Maybe (Int,Int) -- ^ line number and column number to use in errors
|
||||||
> -> String -- ^ the sql source to parse
|
> -> String -- ^ the sql source to parse
|
||||||
|
@ -480,18 +482,18 @@ tref
|
||||||
> from = try (keyword_ "from") *> commaSep1 tref
|
> from = try (keyword_ "from") *> commaSep1 tref
|
||||||
> where
|
> where
|
||||||
> tref = nonJoinTref >>= optionSuffix joinTrefSuffix
|
> tref = nonJoinTref >>= optionSuffix joinTrefSuffix
|
||||||
> nonJoinTref = choice [try (JoinQueryExpr <$> parens queryExpr)
|
> nonJoinTref = choice [try (TRQueryExpr <$> parens queryExpr)
|
||||||
> ,JoinParens <$> parens tref
|
> ,TRParens <$> parens tref
|
||||||
> ,SimpleTableRef <$> identifierString]
|
> ,TRSimple <$> identifierString]
|
||||||
> >>= optionSuffix aliasSuffix
|
> >>= optionSuffix aliasSuffix
|
||||||
> aliasSuffix j =
|
> aliasSuffix j =
|
||||||
> let tableAlias = optional (try $ keyword_ "as") *> identifierString
|
> let tableAlias = optional (try $ keyword_ "as") *> identifierString
|
||||||
> columnAliases = optionMaybe $ try $ parens
|
> columnAliases = optionMaybe $ try $ parens
|
||||||
> $ commaSep1 identifierString
|
> $ commaSep1 identifierString
|
||||||
> in option j (JoinAlias j <$> try tableAlias <*> try columnAliases)
|
> in option j (TRAlias j <$> try tableAlias <*> try columnAliases)
|
||||||
> joinTrefSuffix t = (do
|
> joinTrefSuffix t = (do
|
||||||
> nat <- option False $ try (True <$ (try $ keyword_ "natural"))
|
> nat <- option False $ try (True <$ (try $ keyword_ "natural"))
|
||||||
> JoinTableRef t <$> joinType
|
> TRJoin t <$> joinType
|
||||||
> <*> nonJoinTref
|
> <*> nonJoinTref
|
||||||
> <*> optionMaybe (joinCondition nat))
|
> <*> optionMaybe (joinCondition nat))
|
||||||
> >>= optionSuffix joinTrefSuffix
|
> >>= optionSuffix joinTrefSuffix
|
||||||
|
|
|
@ -169,13 +169,13 @@ back into SQL source text. It attempts to format the output nicely.
|
||||||
> sep [text "from"
|
> sep [text "from"
|
||||||
> ,nest 4 $ commaSep $ map tr ts]
|
> ,nest 4 $ commaSep $ map tr ts]
|
||||||
> where
|
> where
|
||||||
> tr (SimpleTableRef t) = text t
|
> tr (TRSimple t) = text t
|
||||||
> tr (JoinAlias t a cs) =
|
> tr (TRAlias t a cs) =
|
||||||
> tr t <+> text "as" <+> text a
|
> tr t <+> text "as" <+> text a
|
||||||
> <+> maybe empty (parens . commaSep . map text) cs
|
> <+> maybe empty (parens . commaSep . map text) cs
|
||||||
> tr (JoinParens t) = parens $ tr t
|
> tr (TRParens t) = parens $ tr t
|
||||||
> tr (JoinQueryExpr q) = parens $ queryExpr q
|
> tr (TRQueryExpr q) = parens $ queryExpr q
|
||||||
> tr (JoinTableRef t0 jt t1 jc) =
|
> tr (TRJoin t0 jt t1 jc) =
|
||||||
> sep [tr t0
|
> sep [tr t0
|
||||||
> ,joinText jt jc
|
> ,joinText jt jc
|
||||||
> ,tr t1
|
> ,tr t1
|
||||||
|
|
|
@ -20,62 +20,133 @@
|
||||||
> ) where
|
> ) where
|
||||||
|
|
||||||
> -- | Represents a scalar expression
|
> -- | Represents a scalar expression
|
||||||
> data ScalarExpr = NumLit String
|
> data ScalarExpr = -- | a numeric literal optional decimal point, e+-
|
||||||
|
> -- integral exponent, e.g
|
||||||
|
> --
|
||||||
|
> -- * 10
|
||||||
|
> --
|
||||||
|
> -- * 10.
|
||||||
|
> --
|
||||||
|
> -- * .1
|
||||||
|
> --
|
||||||
|
> -- * 10.1
|
||||||
|
> --
|
||||||
|
> -- * 1e5
|
||||||
|
> --
|
||||||
|
> -- * 12.34e-6
|
||||||
|
> NumLit String
|
||||||
|
|
||||||
|
> -- | string literal, currently only basic strings
|
||||||
|
> -- between single quotes without escapes (no
|
||||||
|
> -- single quotes in strings then)
|
||||||
> | StringLit String
|
> | StringLit String
|
||||||
> | IntervalLit String -- text of interval
|
> -- | text of interval literal, units of interval
|
||||||
> String -- units of interval
|
> -- precision, e.g. interval 3 days (3)
|
||||||
> (Maybe Int) -- precision
|
> | IntervalLit String
|
||||||
|
> String
|
||||||
|
> (Maybe Int)
|
||||||
|
> -- | identifier without dots
|
||||||
> | Iden String
|
> | Iden String
|
||||||
|
> -- | identifier with one dot
|
||||||
> | Iden2 String String
|
> | Iden2 String String
|
||||||
|
> -- | star
|
||||||
> | Star
|
> | Star
|
||||||
|
> -- | star with qualifier, e.g t.*
|
||||||
> | Star2 String
|
> | Star2 String
|
||||||
|
> -- | function application (anything that looks
|
||||||
|
> -- like c style function application syntactically)
|
||||||
> | App String [ScalarExpr]
|
> | App String [ScalarExpr]
|
||||||
|
> -- | aggregate application, which adds distinct or
|
||||||
|
> -- all, and order by, to regular function
|
||||||
|
> -- application
|
||||||
> | AggregateApp String (Maybe Duplicates)
|
> | AggregateApp String (Maybe Duplicates)
|
||||||
> [ScalarExpr]
|
> [ScalarExpr]
|
||||||
> [(ScalarExpr,Direction)]
|
> [(ScalarExpr,Direction)]
|
||||||
|
> -- | window application, which adds over
|
||||||
|
> -- (partition by a order by b) to regular function
|
||||||
|
> -- application. Explicit frames are not currently
|
||||||
|
> -- supported
|
||||||
> | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr,Direction)]
|
> | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr,Direction)]
|
||||||
> -- the binop, prefixop and postfix op
|
> -- | Infix binary operators. This is used for
|
||||||
> -- are used for symbol and keyword operators
|
> -- symbol operators (a + b), keyword operators (a
|
||||||
> -- these are used even for the multiple keyword
|
> -- and b) and multiple keyword operators (a is
|
||||||
> -- operators
|
> -- similar to b)
|
||||||
> | BinOp ScalarExpr String ScalarExpr
|
> | BinOp ScalarExpr String ScalarExpr
|
||||||
|
> -- | Prefix unary operators. This is used for
|
||||||
|
> -- symbol operators, keyword operators and
|
||||||
|
> -- multiple keyword operators
|
||||||
> | PrefixOp String ScalarExpr
|
> | PrefixOp String ScalarExpr
|
||||||
|
> -- | Postfix unary operators. This is used for
|
||||||
|
> -- symbol operators, keyword operators and multiple
|
||||||
|
> -- keyword operators
|
||||||
> | PostfixOp String ScalarExpr
|
> | PostfixOp String ScalarExpr
|
||||||
> -- the special op is used for ternary, mixfix and other non orthodox operators
|
> -- | Used for ternary, mixfix and other non
|
||||||
|
> -- orthodox operators, including the function
|
||||||
|
> -- looking calls which use keywords instead of
|
||||||
|
> -- commas to separate the arguments,
|
||||||
|
> -- e.g. substring(t from 1 to 5)
|
||||||
> | SpecialOp String [ScalarExpr]
|
> | SpecialOp String [ScalarExpr]
|
||||||
|
> -- | case expression. both flavours
|
||||||
|
> -- supported. Multiple condition when branches not
|
||||||
|
> -- currently supported (case when a=4,b=5 then x
|
||||||
|
> -- end)
|
||||||
> | Case (Maybe ScalarExpr) -- test value
|
> | Case (Maybe ScalarExpr) -- test value
|
||||||
> [(ScalarExpr,ScalarExpr)] -- when branches
|
> [(ScalarExpr,ScalarExpr)] -- when branches
|
||||||
> (Maybe ScalarExpr) -- else value
|
> (Maybe ScalarExpr) -- else value
|
||||||
> | Parens ScalarExpr
|
> | Parens ScalarExpr
|
||||||
|
> -- | cast(a as typename)
|
||||||
> | Cast ScalarExpr TypeName
|
> | Cast ScalarExpr TypeName
|
||||||
|
> -- | prefix 'typed literal', e.g. int '42'
|
||||||
> | CastOp TypeName String
|
> | CastOp TypeName String
|
||||||
|
> -- | exists, all, any, some subqueries
|
||||||
> | SubQueryExpr SubQueryExprType QueryExpr
|
> | SubQueryExpr SubQueryExprType QueryExpr
|
||||||
|
> -- | in list literal and in subquery, if the bool
|
||||||
|
> -- is false it means not in was used ('a not in
|
||||||
|
> -- (1,2)')
|
||||||
> | In Bool -- true if in, false if not in
|
> | In Bool -- true if in, false if not in
|
||||||
> ScalarExpr InThing
|
> ScalarExpr InThing
|
||||||
> deriving (Eq,Show)
|
> deriving (Eq,Show)
|
||||||
|
|
||||||
|
> -- | Represents a type name, used in casts.
|
||||||
> data TypeName = TypeName String deriving (Eq,Show)
|
> data TypeName = TypeName String deriving (Eq,Show)
|
||||||
|
|
||||||
|
|
||||||
> -- Represents 'expr in (scalar expression list)', and 'expr in
|
> -- | Used for 'expr in (scalar expression list)', and 'expr in
|
||||||
> -- (subquery)' syntax
|
> -- | (subquery)' syntax
|
||||||
> data InThing = InList [ScalarExpr]
|
> data InThing = InList [ScalarExpr]
|
||||||
> | InQueryExpr QueryExpr
|
> | InQueryExpr QueryExpr
|
||||||
> deriving (Eq,Show)
|
> deriving (Eq,Show)
|
||||||
|
|
||||||
> -- | A subquery in a scalar expression
|
> -- | A subquery in a scalar expression
|
||||||
> data SubQueryExprType = SqExists | SqSq | SqAll | SqSome | SqAny
|
> data SubQueryExprType
|
||||||
|
> = -- | exists (query expr)
|
||||||
|
> SqExists
|
||||||
|
> -- | a scalar subquery
|
||||||
|
> | SqSq
|
||||||
|
> -- | all (query expr)
|
||||||
|
> | SqAll
|
||||||
|
> -- | some (query expr)
|
||||||
|
> | SqSome
|
||||||
|
> -- | any (query expr)
|
||||||
|
> | SqAny
|
||||||
> deriving (Eq,Show)
|
> deriving (Eq,Show)
|
||||||
|
|
||||||
> -- | Represents a query expression, which can be a select, a 'set
|
> -- | Represents a query expression, which can be:
|
||||||
> -- operator' (union/except/intersect), a common table expression
|
> --
|
||||||
> -- (with), a values expression (not yet supported) or the table
|
> -- * a regular select;
|
||||||
> -- syntax - 'table t', shorthand for 'select * from t' (not yet
|
> --
|
||||||
> -- supported).
|
> -- * a set operator (union, except, intersect);
|
||||||
|
> --
|
||||||
|
> -- * a common table expression (with);
|
||||||
|
> --
|
||||||
|
> -- * a values expression (not yet supported);
|
||||||
|
> --
|
||||||
|
> -- * or the table syntax - 'table t', shorthand for 'select * from
|
||||||
|
> -- t' (not yet supported).
|
||||||
> data QueryExpr
|
> data QueryExpr
|
||||||
> = Select
|
> = Select
|
||||||
> {qeDuplicates :: Duplicates
|
> {qeDuplicates :: Duplicates
|
||||||
> ,qeSelectList :: [(Maybe String,ScalarExpr)]
|
> ,qeSelectList :: [(Maybe String,ScalarExpr)] -- ^ the column aliases and the expressions
|
||||||
> ,qeFrom :: [TableRef]
|
> ,qeFrom :: [TableRef]
|
||||||
> ,qeWhere :: Maybe ScalarExpr
|
> ,qeWhere :: Maybe ScalarExpr
|
||||||
> ,qeGroupBy :: [ScalarExpr]
|
> ,qeGroupBy :: [ScalarExpr]
|
||||||
|
@ -101,14 +172,14 @@ I'm not sure if this is valid syntax or not
|
||||||
|
|
||||||
> -- | represents the Distinct or All keywords, which can be used
|
> -- | represents the Distinct or All keywords, which can be used
|
||||||
> -- before a select list, in an aggregate/window function
|
> -- before a select list, in an aggregate/window function
|
||||||
> -- application, or in a query expression 'set operator'
|
> -- application, or in a query expression set operator
|
||||||
> data Duplicates = Distinct | All deriving (Eq,Show)
|
> data Duplicates = Distinct | All deriving (Eq,Show)
|
||||||
|
|
||||||
> -- | The direction for a column in order by.
|
> -- | The direction for a column in order by.
|
||||||
> data Direction = Asc | Desc deriving (Eq,Show)
|
> data Direction = Asc | Desc deriving (Eq,Show)
|
||||||
> -- | Query expression 'set operators'
|
> -- | Query expression set operators
|
||||||
> data CombineOp = Union | Except | Intersect deriving (Eq,Show)
|
> data CombineOp = Union | Except | Intersect deriving (Eq,Show)
|
||||||
> -- | Corresponding, an option for the 'set operators'
|
> -- | Corresponding, an option for the set operators
|
||||||
> data Corresponding = Corresponding | Respectively deriving (Eq,Show)
|
> data Corresponding = Corresponding | Respectively deriving (Eq,Show)
|
||||||
|
|
||||||
> -- | helper/'default' value for query exprs to make creating query expr values a little easier
|
> -- | helper/'default' value for query exprs to make creating query expr values a little easier
|
||||||
|
@ -124,11 +195,16 @@ I'm not sure if this is valid syntax or not
|
||||||
> ,qeOffset = Nothing}
|
> ,qeOffset = Nothing}
|
||||||
|
|
||||||
> -- | Represents a entry in the csv of tables in the from clause.
|
> -- | Represents a entry in the csv of tables in the from clause.
|
||||||
> data TableRef = SimpleTableRef String -- from t
|
> data TableRef = -- | from t
|
||||||
> | JoinTableRef TableRef JoinType TableRef (Maybe JoinCondition) -- from a join b
|
> TRSimple String
|
||||||
> | JoinParens TableRef -- from (a)
|
> -- | from a join b
|
||||||
> | JoinAlias TableRef String (Maybe [String]) -- from a as b(c,d)
|
> | TRJoin TableRef JoinType TableRef (Maybe JoinCondition)
|
||||||
> | JoinQueryExpr QueryExpr -- from (query expr)
|
> -- | from (a)
|
||||||
|
> | TRParens TableRef
|
||||||
|
> -- | from a as b(c,d)
|
||||||
|
> | TRAlias TableRef String (Maybe [String])
|
||||||
|
> -- | from (query expr)
|
||||||
|
> | TRQueryExpr QueryExpr
|
||||||
> deriving (Eq,Show)
|
> deriving (Eq,Show)
|
||||||
|
|
||||||
TODO: add function table ref
|
TODO: add function table ref
|
||||||
|
@ -140,5 +216,5 @@ TODO: add function table ref
|
||||||
> -- | The join condition.
|
> -- | The join condition.
|
||||||
> data JoinCondition = JoinOn ScalarExpr -- ^ on expr
|
> data JoinCondition = JoinOn ScalarExpr -- ^ on expr
|
||||||
> | JoinUsing [String] -- ^ using (column list)
|
> | JoinUsing [String] -- ^ using (column list)
|
||||||
> | JoinNatural -- ^ natural join was specified
|
> | JoinNatural -- ^ natural join was used
|
||||||
> deriving (Eq,Show)
|
> deriving (Eq,Show)
|
||||||
|
|
68
Tests.lhs
68
Tests.lhs
|
@ -143,7 +143,7 @@
|
||||||
> where
|
> where
|
||||||
> ms = makeSelect
|
> ms = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "a")]
|
> {qeSelectList = [(Nothing,Iden "a")]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> }
|
> }
|
||||||
|
|
||||||
> miscOps :: TestItem
|
> miscOps :: TestItem
|
||||||
|
@ -240,7 +240,7 @@
|
||||||
> ms d = makeSelect
|
> ms d = makeSelect
|
||||||
> {qeDuplicates = d
|
> {qeDuplicates = d
|
||||||
> ,qeSelectList = [(Nothing,Iden "a")]
|
> ,qeSelectList = [(Nothing,Iden "a")]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]}
|
> ,qeFrom = [TRSimple "t"]}
|
||||||
|
|
||||||
> selectLists :: TestItem
|
> selectLists :: TestItem
|
||||||
> selectLists = Group "selectLists" $ map (uncurry TestQueryExpr)
|
> selectLists = Group "selectLists" $ map (uncurry TestQueryExpr)
|
||||||
|
@ -266,50 +266,48 @@
|
||||||
> from :: TestItem
|
> from :: TestItem
|
||||||
> from = Group "from" $ map (uncurry TestQueryExpr)
|
> from = Group "from" $ map (uncurry TestQueryExpr)
|
||||||
> [("select a from t"
|
> [("select a from t"
|
||||||
> ,ms [SimpleTableRef "t"])
|
> ,ms [TRSimple "t"])
|
||||||
> ,("select a from t,u"
|
> ,("select a from t,u"
|
||||||
> ,ms [SimpleTableRef "t", SimpleTableRef "u"])
|
> ,ms [TRSimple "t", TRSimple "u"])
|
||||||
> ,("select a from t inner join u on expr"
|
> ,("select a from t inner join u on expr"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t") JInner (SimpleTableRef "u")
|
> ,ms [TRJoin (TRSimple "t") JInner (TRSimple "u")
|
||||||
> (Just $ JoinOn $ Iden "expr")])
|
> (Just $ JoinOn $ Iden "expr")])
|
||||||
> ,("select a from t left join u on expr"
|
> ,("select a from t left join u on expr"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t") JLeft (SimpleTableRef "u")
|
> ,ms [TRJoin (TRSimple "t") JLeft (TRSimple "u")
|
||||||
> (Just $ JoinOn $ Iden "expr")])
|
> (Just $ JoinOn $ Iden "expr")])
|
||||||
> ,("select a from t right join u on expr"
|
> ,("select a from t right join u on expr"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t") JRight (SimpleTableRef "u")
|
> ,ms [TRJoin (TRSimple "t") JRight (TRSimple "u")
|
||||||
> (Just $ JoinOn $ Iden "expr")])
|
> (Just $ JoinOn $ Iden "expr")])
|
||||||
> ,("select a from t full join u on expr"
|
> ,("select a from t full join u on expr"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t") JFull (SimpleTableRef "u")
|
> ,ms [TRJoin (TRSimple "t") JFull (TRSimple "u")
|
||||||
> (Just $ JoinOn $ Iden "expr")])
|
> (Just $ JoinOn $ Iden "expr")])
|
||||||
> ,("select a from t cross join u"
|
> ,("select a from t cross join u"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t")
|
> ,ms [TRJoin (TRSimple "t")
|
||||||
> JCross (SimpleTableRef "u") Nothing])
|
> JCross (TRSimple "u") Nothing])
|
||||||
> ,("select a from t natural inner join u"
|
> ,("select a from t natural inner join u"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t") JInner (SimpleTableRef "u")
|
> ,ms [TRJoin (TRSimple "t") JInner (TRSimple "u")
|
||||||
> (Just JoinNatural)])
|
> (Just JoinNatural)])
|
||||||
> ,("select a from t inner join u using(a,b)"
|
> ,("select a from t inner join u using(a,b)"
|
||||||
> ,ms [JoinTableRef (SimpleTableRef "t") JInner (SimpleTableRef "u")
|
> ,ms [TRJoin (TRSimple "t") JInner (TRSimple "u")
|
||||||
> (Just $ JoinUsing ["a", "b"])])
|
> (Just $ JoinUsing ["a", "b"])])
|
||||||
> ,("select a from (select a from t)"
|
> ,("select a from (select a from t)"
|
||||||
> ,ms [JoinQueryExpr $ ms [SimpleTableRef "t"]])
|
> ,ms [TRQueryExpr $ ms [TRSimple "t"]])
|
||||||
> ,("select a from t as u"
|
> ,("select a from t as u"
|
||||||
> ,ms [JoinAlias (SimpleTableRef "t") "u" Nothing])
|
> ,ms [TRAlias (TRSimple "t") "u" Nothing])
|
||||||
> ,("select a from t u"
|
> ,("select a from t u"
|
||||||
> ,ms [JoinAlias (SimpleTableRef "t") "u" Nothing])
|
> ,ms [TRAlias (TRSimple "t") "u" Nothing])
|
||||||
> ,("select a from t u(b)"
|
> ,("select a from t u(b)"
|
||||||
> ,ms [JoinAlias (SimpleTableRef "t") "u" $ Just ["b"]])
|
> ,ms [TRAlias (TRSimple "t") "u" $ Just ["b"]])
|
||||||
> ,("select a from (t cross join u) as u"
|
> ,("select a from (t cross join u) as u"
|
||||||
> ,ms [JoinAlias (JoinParens $
|
> ,ms [TRAlias (TRParens $
|
||||||
> JoinTableRef (SimpleTableRef "t")
|
> TRJoin (TRSimple "t") JCross (TRSimple "u") Nothing)
|
||||||
> JCross
|
|
||||||
> (SimpleTableRef "u") Nothing)
|
|
||||||
> "u" Nothing])
|
> "u" Nothing])
|
||||||
> -- todo: not sure if the associativity is correct
|
> -- todo: not sure if the associativity is correct
|
||||||
> ,("select a from t cross join u cross join v",
|
> ,("select a from t cross join u cross join v",
|
||||||
> ms [JoinTableRef
|
> ms [TRJoin
|
||||||
> (JoinTableRef (SimpleTableRef "t")
|
> (TRJoin (TRSimple "t")
|
||||||
> JCross (SimpleTableRef "u") Nothing)
|
> JCross (TRSimple "u") Nothing)
|
||||||
> JCross (SimpleTableRef "v") Nothing])
|
> JCross (TRSimple "v") Nothing])
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms f = makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
> ms f = makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
||||||
|
@ -319,7 +317,7 @@
|
||||||
> whereClause = Group "whereClause" $ map (uncurry TestQueryExpr)
|
> whereClause = Group "whereClause" $ map (uncurry TestQueryExpr)
|
||||||
> [("select a from t where a = 5"
|
> [("select a from t where a = 5"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
> ,makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit "5")})
|
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit "5")})
|
||||||
> ]
|
> ]
|
||||||
|
|
||||||
|
@ -328,14 +326,14 @@
|
||||||
> [("select a,sum(b) from t group by a"
|
> [("select a,sum(b) from t group by a"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
||||||
> ,(Nothing, App "sum" [Iden "b"])]
|
> ,(Nothing, App "sum" [Iden "b"])]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = [Iden "a"]
|
> ,qeGroupBy = [Iden "a"]
|
||||||
> })
|
> })
|
||||||
> ,("select a,b,sum(c) from t group by a,b"
|
> ,("select a,b,sum(c) from t group by a,b"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
||||||
> ,(Nothing, Iden "b")
|
> ,(Nothing, Iden "b")
|
||||||
> ,(Nothing, App "sum" [Iden "c"])]
|
> ,(Nothing, App "sum" [Iden "c"])]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = [Iden "a",Iden "b"]
|
> ,qeGroupBy = [Iden "a",Iden "b"]
|
||||||
> })
|
> })
|
||||||
> ]
|
> ]
|
||||||
|
@ -345,7 +343,7 @@
|
||||||
> [("select a,sum(b) from t group by a having sum(b) > 5"
|
> [("select a,sum(b) from t group by a having sum(b) > 5"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
||||||
> ,(Nothing, App "sum" [Iden "b"])]
|
> ,(Nothing, App "sum" [Iden "b"])]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = [Iden "a"]
|
> ,qeGroupBy = [Iden "a"]
|
||||||
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"])
|
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"])
|
||||||
> ">" (NumLit "5")
|
> ">" (NumLit "5")
|
||||||
|
@ -365,7 +363,7 @@
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms o = makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
> ms o = makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeOrderBy = o}
|
> ,qeOrderBy = o}
|
||||||
|
|
||||||
> limit :: TestItem
|
> limit :: TestItem
|
||||||
|
@ -378,7 +376,7 @@
|
||||||
> where
|
> where
|
||||||
> ms l o = makeSelect
|
> ms l o = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "a")]
|
> {qeSelectList = [(Nothing,Iden "a")]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeLimit = l
|
> ,qeLimit = l
|
||||||
> ,qeOffset = o}
|
> ,qeOffset = o}
|
||||||
|
|
||||||
|
@ -401,10 +399,10 @@
|
||||||
> where
|
> where
|
||||||
> ms1 = makeSelect
|
> ms1 = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "a")]
|
> {qeSelectList = [(Nothing,Iden "a")]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]}
|
> ,qeFrom = [TRSimple "t"]}
|
||||||
> ms2 = makeSelect
|
> ms2 = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "b")]
|
> {qeSelectList = [(Nothing,Iden "b")]
|
||||||
> ,qeFrom = [SimpleTableRef "u"]}
|
> ,qeFrom = [TRSimple "u"]}
|
||||||
|
|
||||||
|
|
||||||
> withQueries :: TestItem
|
> withQueries :: TestItem
|
||||||
|
@ -419,7 +417,7 @@
|
||||||
> where
|
> where
|
||||||
> ms c t = makeSelect
|
> ms c t = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden c)]
|
> {qeSelectList = [(Nothing,Iden c)]
|
||||||
> ,qeFrom = [SimpleTableRef t]}
|
> ,qeFrom = [TRSimple t]}
|
||||||
> ms1 = ms "a" "t"
|
> ms1 = ms "a" "t"
|
||||||
> ms2 = ms "a" "u"
|
> ms2 = ms "a" "u"
|
||||||
> ms3 = ms "a" "x"
|
> ms3 = ms "a" "x"
|
||||||
|
@ -430,7 +428,7 @@
|
||||||
> [("select count(*) from t"
|
> [("select count(*) from t"
|
||||||
> ,makeSelect
|
> ,makeSelect
|
||||||
> {qeSelectList = [(Nothing, App "count" [Star])]
|
> {qeSelectList = [(Nothing, App "count" [Star])]
|
||||||
> ,qeFrom = [SimpleTableRef "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> }
|
> }
|
||||||
> )
|
> )
|
||||||
> ,("select a, sum(c+d) as s\n\
|
> ,("select a, sum(c+d) as s\n\
|
||||||
|
@ -444,7 +442,7 @@
|
||||||
> ,(Just "s"
|
> ,(Just "s"
|
||||||
> ,App "sum" [BinOp (Iden "c")
|
> ,App "sum" [BinOp (Iden "c")
|
||||||
> "+" (Iden "d")])]
|
> "+" (Iden "d")])]
|
||||||
> ,qeFrom = [SimpleTableRef "t", SimpleTableRef "u"]
|
> ,qeFrom = [TRSimple "t", TRSimple "u"]
|
||||||
> ,qeWhere = Just $ BinOp (Iden "a") ">" (NumLit "5")
|
> ,qeWhere = Just $ BinOp (Iden "a") ">" (NumLit "5")
|
||||||
> ,qeGroupBy = [Iden "a"]
|
> ,qeGroupBy = [Iden "a"]
|
||||||
> ,qeHaving = Just $ BinOp (App "count" [NumLit "1"])
|
> ,qeHaving = Just $ BinOp (App "count" [NumLit "1"])
|
||||||
|
|
Loading…
Reference in a new issue