-- Some tests for parsing full queries. {-# LANGUAGE OverloadedStrings #-} module Language.SQL.SimpleSQL.FullQueries (fullQueriesTests) where import Language.SQL.SimpleSQL.TestTypes import Language.SQL.SimpleSQL.Syntax fullQueriesTests :: TestItem fullQueriesTests = Group "queries" $ map (uncurry (TestQueryExpr ansi2011)) [("select count(*) from t" ,toQueryExpr $ makeSelect {msSelectList = [(App [Name Nothing "count"] [Star], Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] } ) ,("select a, sum(c+d) as s\n\ \ from t,u\n\ \ where a > 5\n\ \ group by a\n\ \ having count(1) > 5\n\ \ order by s" ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"], Nothing) ,(App [Name Nothing "sum"] [BinOp (Iden [Name Nothing "c"]) [Name Nothing "+"] (Iden [Name Nothing "d"])] ,Just $ Name Nothing "s")] ,msFrom = [TRSimple [Name Nothing "t"], TRSimple [Name Nothing "u"]] ,msWhere = Just $ BinOp (Iden [Name Nothing "a"]) [Name Nothing ">"] (NumLit "5") ,msGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] ,msHaving = Just $ BinOp (App [Name Nothing "count"] [NumLit "1"]) [Name Nothing ">"] (NumLit "5") ,msOrderBy = [SortSpec (Iden [Name Nothing "s"]) DirDefault NullsOrderDefault] } ) ]