1
Fork 0

add support for 'table t' syntax

This commit is contained in:
Jake Wheat 2013-12-17 13:58:44 +02:00
parent 4308acb982
commit 72b67166d9
6 changed files with 63 additions and 64 deletions
Language/SQL/SimpleSQL

View file

@ -602,7 +602,8 @@ and union, etc..
> queryExpr :: P QueryExpr
> queryExpr =
> choice [with
> ,choice [values,select] >>= optionSuffix queryExprSuffix]
> ,choice [values,table, select]
> >>= optionSuffix queryExprSuffix]
> where
> select = try (keyword_ "select") >>
> Select
@ -617,6 +618,7 @@ and union, etc..
> <*> optionMaybe offset
> values = try (keyword_ "values")
> >> Values <$> commaSep (parens (commaSep scalarExpr))
> table = try (keyword_ "table") >> Table <$> name
> queryExprSuffix :: QueryExpr -> P QueryExpr
> queryExprSuffix qe =

View file

@ -180,6 +180,8 @@
> queryExpr (Values vs) =
> text "values"
> <+> nest 7 (commaSep (map (parens . commaSep . map scalarExpr) vs))
> queryExpr (Table t) = text "table" <+> name t
> alias :: Alias -> Doc
> alias (Alias nm cols) =

View file

@ -164,25 +164,13 @@
> ,qeViews :: [(Alias,QueryExpr)]
> ,qeQueryExpression :: QueryExpr}
> | Values [[ScalarExpr]]
> | Table Name
> deriving (Eq,Show,Read)
TODO: add queryexpr parens to deal with e.g.
(select 1 union select 2) union select 3
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)
> -- | The direction for a column in order by.
> data Direction = Asc | Desc deriving (Eq,Show,Read)
> -- | Query expression set operators
> data CombineOp = Union | Except | Intersect deriving (Eq,Show,Read)
> -- | Corresponding, an option for the set operators
> data Corresponding = Corresponding | Respectively deriving (Eq,Show,Read)
> -- | helper/'default' value for query exprs to make creating query
> -- expr values a little easier
> makeSelect :: QueryExpr
@ -196,6 +184,19 @@ I'm not sure if this is valid syntax or not.
> ,qeLimit = Nothing
> ,qeOffset = Nothing}
> -- | 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)
> -- | The direction for a column in order by.
> data Direction = Asc | Desc deriving (Eq,Show,Read)
> -- | Query expression set operators
> data CombineOp = Union | Except | Intersect deriving (Eq,Show,Read)
> -- | Corresponding, an option for the set operators
> data Corresponding = Corresponding | Respectively deriving (Eq,Show,Read)
> -- | Represents a entry in the csv of tables in the from clause.
> data TableRef = -- | from t
> TRSimple Name
@ -213,6 +214,9 @@ I'm not sure if this is valid syntax or not.
> | TRLateral TableRef
> deriving (Eq,Show,Read)
> -- | Represents an alias for a table valued expression, used in with
> -- queries and in from alias, e.g. select a from t u, select a from t u(b),
> -- with a(c) as select 1, select * from a;
> data Alias = Alias Name (Maybe [Name])
> deriving (Eq,Show,Read)