1
Fork 0

add support for full table aliases

This commit is contained in:
Jake Wheat 2013-12-14 00:37:34 +02:00
parent d005dc1706
commit 15c83555ff
4 changed files with 11 additions and 6 deletions

View file

@ -507,7 +507,8 @@ attempt to fix the precedence and associativity. Doesn't work
> ,return Nothing > ,return Nothing
> ] > ]
> alias j = let a1 = optional (try (keyword_ "as")) *> identifierString > alias j = let a1 = optional (try (keyword_ "as")) *> identifierString
> in option j (JoinAlias j <$> try a1) > a2 = optionMaybe (try $ parens (commaSep1 identifierString))
> in option j (JoinAlias j <$> try a1 <*> try a2)
> optionalScalarExpr :: String -> P (Maybe ScalarExpr) > optionalScalarExpr :: String -> P (Maybe ScalarExpr)
> optionalScalarExpr k = optionMaybe (try (keyword_ k) *> scalarExpr) > optionalScalarExpr k = optionMaybe (try (keyword_ k) *> scalarExpr)

View file

@ -157,7 +157,9 @@ back into SQL source text. It attempts to format the output nicely.
> ,nest 4 $ commaSep $ map tr ts] > ,nest 4 $ commaSep $ map tr ts]
> where > where
> tr (SimpleTableRef t) = text t > tr (SimpleTableRef t) = text t
> tr (JoinAlias t a) = tr t <+> text "as" <+> text a > tr (JoinAlias t a cs) =
> tr t <+> text "as" <+> text a
> <+> maybe empty (\cs' -> parens $ commaSep $ map text cs') cs
> tr (JoinParens t) = parens $ tr t > tr (JoinParens t) = parens $ tr t
> tr (JoinQueryExpr q) = parens $ queryExpr q > tr (JoinQueryExpr q) = parens $ queryExpr q
> tr (JoinTableRef jt t0 t1 jc) = > tr (JoinTableRef jt t0 t1 jc) =

View file

@ -99,7 +99,7 @@
> data TableRef = SimpleTableRef String > data TableRef = SimpleTableRef String
> | JoinTableRef JoinType TableRef TableRef (Maybe JoinCondition) > | JoinTableRef JoinType TableRef TableRef (Maybe JoinCondition)
> | JoinParens TableRef > | JoinParens TableRef
> | JoinAlias TableRef String > | JoinAlias TableRef String (Maybe [String])
> | JoinQueryExpr QueryExpr > | JoinQueryExpr QueryExpr
> deriving (Eq,Show) > deriving (Eq,Show)

View file

@ -289,12 +289,14 @@
> ,("select a from (select a from t)" > ,("select a from (select a from t)"
> ,ms [JoinQueryExpr $ ms [SimpleTableRef "t"]]) > ,ms [JoinQueryExpr $ ms [SimpleTableRef "t"]])
> ,("select a from t as u" > ,("select a from t as u"
> ,ms [JoinAlias (SimpleTableRef "t") "u"]) > ,ms [JoinAlias (SimpleTableRef "t") "u" Nothing])
> ,("select a from t u" > ,("select a from t u"
> ,ms [JoinAlias (SimpleTableRef "t") "u"]) > ,ms [JoinAlias (SimpleTableRef "t") "u" Nothing])
> ,("select a from t u(b)"
> ,ms [JoinAlias (SimpleTableRef "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 $ JoinTableRef Cross (SimpleTableRef "t") > ,ms [JoinAlias (JoinParens $ JoinTableRef Cross (SimpleTableRef "t")
> (SimpleTableRef "u") Nothing) "u"]) > (SimpleTableRef "u") Nothing) "u" Nothing])
> ] > ]
> where > where
> ms f = makeSelect {qeSelectList = [(Nothing,Iden "a")] > ms f = makeSelect {qeSelectList = [(Nothing,Iden "a")]