add partial support for parens at the query expression level
This commit is contained in:
parent
f1ff143457
commit
fc002dc549
4 changed files with 70 additions and 4 deletions
tests/Language/SQL/SimpleSQL
47
tests/Language/SQL/SimpleSQL/QueryExprParens.hs
Normal file
47
tests/Language/SQL/SimpleSQL/QueryExprParens.hs
Normal file
|
@ -0,0 +1,47 @@
|
|||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
module Language.SQL.SimpleSQL.QueryExprParens (queryExprParensTests) where
|
||||
|
||||
import Language.SQL.SimpleSQL.TestTypes
|
||||
import Language.SQL.SimpleSQL.Syntax
|
||||
import Language.SQL.SimpleSQL.TestRunners
|
||||
import Data.Text (Text)
|
||||
import qualified Text.RawString.QQ as R
|
||||
|
||||
queryExprParensTests :: TestItem
|
||||
queryExprParensTests = Group "query expr parens"
|
||||
[q "(select * from t)" $ QueryExprParens $ ms "t"
|
||||
,q "select * from t except (select * from u except select * from v)"
|
||||
$ (ms "t") `sexcept` QueryExprParens (ms "u" `sexcept` ms "v")
|
||||
|
||||
,q "(select * from t except select * from u) except select * from v"
|
||||
$ QueryExprParens (ms "t" `sexcept` ms "u") `sexcept` ms "v"
|
||||
|
||||
,q [R.r|
|
||||
select * from t
|
||||
union
|
||||
with a as (select * from u)
|
||||
select * from a
|
||||
|]
|
||||
$ ms "t" `sunion` with [("a", ms "u")] (ms "a")
|
||||
|
||||
,q [R.r|
|
||||
select * from t
|
||||
union
|
||||
(with a as (select * from u)
|
||||
select * from a)
|
||||
|]
|
||||
$ ms "t" `sunion` QueryExprParens (with [("a", ms "u")] (ms "a"))
|
||||
]
|
||||
where
|
||||
q :: HasCallStack => Text -> QueryExpr -> TestItem
|
||||
q src ast = testQueryExpr ansi2011 src ast
|
||||
ms t = toQueryExpr $ makeSelect
|
||||
{msSelectList = [(Star,Nothing)]
|
||||
,msFrom = [TRSimple [Name Nothing t]]}
|
||||
sexcept = so Except
|
||||
sunion = so Union
|
||||
so op a b = QueryExprSetOp a op SQDefault Respectively b
|
||||
with es s =
|
||||
With False (flip map es $ \(n,sn) -> (Alias (Name Nothing n) Nothing ,sn)) s
|
|
@ -25,6 +25,7 @@ import Language.SQL.SimpleSQL.GroupBy
|
|||
import Language.SQL.SimpleSQL.Postgres
|
||||
import Language.SQL.SimpleSQL.QueryExprComponents
|
||||
import Language.SQL.SimpleSQL.QueryExprs
|
||||
import Language.SQL.SimpleSQL.QueryExprParens
|
||||
import Language.SQL.SimpleSQL.TableRefs
|
||||
import Language.SQL.SimpleSQL.ScalarExprs
|
||||
import Language.SQL.SimpleSQL.Odbc
|
||||
|
@ -59,6 +60,7 @@ testData =
|
|||
,odbcTests
|
||||
,queryExprComponentTests
|
||||
,queryExprsTests
|
||||
,queryExprParensTests
|
||||
,tableRefTests
|
||||
,groupByTests
|
||||
,fullQueriesTests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue