2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-13 15:04:48 +01:00
|
|
|
> module Language.SQL.SimpleSQL.Syntax
|
2013-12-13 17:50:41 +01:00
|
|
|
> (ScalarExpr(..)
|
|
|
|
> ,TypeName(..)
|
2013-12-13 19:43:28 +01:00
|
|
|
> ,SubQueryExprType(..)
|
2013-12-13 20:00:06 +01:00
|
|
|
> ,InThing(..)
|
2013-12-13 17:50:41 +01:00
|
|
|
> ,QueryExpr(..)
|
2013-12-13 15:04:48 +01:00
|
|
|
> ,makeSelect
|
2013-12-13 17:50:41 +01:00
|
|
|
> ,Duplicates(..)
|
|
|
|
> ,Direction(..)
|
2013-12-13 22:41:12 +01:00
|
|
|
> ,CombineOp(..)
|
2013-12-13 22:49:22 +01:00
|
|
|
> ,Corresponding(..)
|
2013-12-13 15:04:48 +01:00
|
|
|
> ,TableRef(..)
|
|
|
|
> ,JoinType(..)
|
|
|
|
> ,JoinCondition(..)
|
|
|
|
> ) where
|
2013-12-13 11:39:26 +01:00
|
|
|
|
|
|
|
|
2013-12-13 16:00:22 +01:00
|
|
|
> data ScalarExpr = NumLit String
|
|
|
|
> | StringLit String
|
2013-12-13 23:07:45 +01:00
|
|
|
> | IntervalLit String -- text of interval
|
|
|
|
> String -- units of interval
|
|
|
|
> (Maybe Int) -- precision
|
2013-12-13 16:00:22 +01:00
|
|
|
> | Iden String
|
|
|
|
> | Iden2 String String
|
2013-12-13 11:39:26 +01:00
|
|
|
> | Star
|
|
|
|
> | Star2 String
|
|
|
|
> | App String [ScalarExpr]
|
2013-12-13 22:18:30 +01:00
|
|
|
> | AggregateApp String (Maybe Duplicates)
|
|
|
|
> [ScalarExpr]
|
|
|
|
> [(ScalarExpr,Direction)]
|
2013-12-13 22:31:36 +01:00
|
|
|
> | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr,Direction)]
|
2013-12-13 20:26:14 +01:00
|
|
|
> -- the binop, prefixop and postfix op
|
|
|
|
> -- are used for symbol and keyword operators
|
2013-12-13 20:34:59 +01:00
|
|
|
> -- these are used even for the multiple keyword
|
|
|
|
> -- operators
|
2013-12-13 20:26:14 +01:00
|
|
|
> | BinOp String ScalarExpr ScalarExpr
|
|
|
|
> | PrefixOp String ScalarExpr
|
|
|
|
> | PostfixOp String ScalarExpr
|
|
|
|
> -- the special op is used for ternary, mixfix and other non orthodox operators
|
|
|
|
> | SpecialOp String [ScalarExpr]
|
2013-12-13 11:39:26 +01:00
|
|
|
> | Case (Maybe ScalarExpr) -- test value
|
|
|
|
> [(ScalarExpr,ScalarExpr)] -- when branches
|
|
|
|
> (Maybe ScalarExpr) -- else value
|
|
|
|
> | Parens ScalarExpr
|
2013-12-13 17:50:41 +01:00
|
|
|
> | Cast ScalarExpr TypeName
|
2013-12-13 19:24:20 +01:00
|
|
|
> | CastOp TypeName String
|
2013-12-13 19:43:28 +01:00
|
|
|
> | SubQueryExpr SubQueryExprType QueryExpr
|
2013-12-13 20:00:06 +01:00
|
|
|
> | In Bool -- true if in, false if not in
|
|
|
|
> ScalarExpr InThing
|
2013-12-13 11:39:26 +01:00
|
|
|
> deriving (Eq,Show)
|
|
|
|
|
2013-12-13 17:50:41 +01:00
|
|
|
> data TypeName = TypeName String deriving (Eq,Show)
|
2013-12-13 20:00:06 +01:00
|
|
|
> data InThing = InList [ScalarExpr]
|
|
|
|
> | InQueryExpr QueryExpr
|
|
|
|
> deriving (Eq,Show)
|
2013-12-13 17:50:41 +01:00
|
|
|
|
2013-12-13 20:00:06 +01:00
|
|
|
> data SubQueryExprType = SqExists | SqSq | SqAll | SqSome | SqAny
|
2013-12-13 19:43:28 +01:00
|
|
|
> deriving (Eq,Show)
|
|
|
|
|
2013-12-13 11:39:26 +01:00
|
|
|
> data QueryExpr
|
|
|
|
> = Select
|
2013-12-13 16:27:02 +01:00
|
|
|
> {qeDuplicates :: Duplicates
|
|
|
|
> ,qeSelectList :: [(Maybe String,ScalarExpr)]
|
2013-12-13 11:39:26 +01:00
|
|
|
> ,qeFrom :: [TableRef]
|
|
|
|
> ,qeWhere :: Maybe ScalarExpr
|
|
|
|
> ,qeGroupBy :: [ScalarExpr]
|
|
|
|
> ,qeHaving :: Maybe ScalarExpr
|
2013-12-13 16:08:10 +01:00
|
|
|
> ,qeOrderBy :: [(ScalarExpr,Direction)]
|
2013-12-13 16:27:02 +01:00
|
|
|
> ,qeLimit :: Maybe ScalarExpr
|
|
|
|
> ,qeOffset :: Maybe ScalarExpr
|
2013-12-13 22:41:12 +01:00
|
|
|
> }
|
|
|
|
> | CombineQueryExpr
|
|
|
|
> {qe1 :: QueryExpr
|
|
|
|
> ,qeCombOp :: CombineOp
|
2013-12-13 22:49:22 +01:00
|
|
|
> ,qeDuplicates :: Duplicates
|
|
|
|
> ,qeCorresponding :: Corresponding
|
2013-12-13 22:41:12 +01:00
|
|
|
> ,qe2 :: QueryExpr
|
|
|
|
> }
|
|
|
|
> deriving (Eq,Show)
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-13 16:27:02 +01:00
|
|
|
> data Duplicates = Distinct | All deriving (Eq,Show)
|
2013-12-13 16:08:10 +01:00
|
|
|
> data Direction = Asc | Desc deriving (Eq,Show)
|
2013-12-13 22:41:12 +01:00
|
|
|
> data CombineOp = Union | Except | Intersect deriving (Eq,Show)
|
2013-12-13 22:49:22 +01:00
|
|
|
> data Corresponding = Corresponding | Respectively deriving (Eq,Show)
|
2013-12-13 16:08:10 +01:00
|
|
|
|
2013-12-13 11:39:26 +01:00
|
|
|
> makeSelect :: QueryExpr
|
2013-12-13 16:27:02 +01:00
|
|
|
> makeSelect = Select {qeDuplicates = All
|
|
|
|
> ,qeSelectList = []
|
2013-12-13 11:39:26 +01:00
|
|
|
> ,qeFrom = []
|
|
|
|
> ,qeWhere = Nothing
|
|
|
|
> ,qeGroupBy = []
|
|
|
|
> ,qeHaving = Nothing
|
2013-12-13 16:27:02 +01:00
|
|
|
> ,qeOrderBy = []
|
|
|
|
> ,qeLimit = Nothing
|
|
|
|
> ,qeOffset = Nothing}
|
2013-12-13 11:39:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
> data TableRef = SimpleTableRef String
|
|
|
|
> | JoinTableRef JoinType TableRef TableRef (Maybe JoinCondition)
|
|
|
|
> | JoinParens TableRef
|
2013-12-13 23:37:34 +01:00
|
|
|
> | JoinAlias TableRef String (Maybe [String])
|
2013-12-13 11:39:26 +01:00
|
|
|
> | JoinQueryExpr QueryExpr
|
|
|
|
> deriving (Eq,Show)
|
|
|
|
|
|
|
|
> data JoinType = Inner | JLeft | JRight | Full | Cross
|
|
|
|
> deriving (Eq,Show)
|
|
|
|
|
|
|
|
> data JoinCondition = JoinOn ScalarExpr
|
|
|
|
> | JoinUsing [String]
|
|
|
|
> | JoinNatural
|
|
|
|
> deriving (Eq,Show)
|