1
Fork 0
simple-sql-parser/Language/SQL/SimpleSQL/Syntax.lhs

113 lines
4 KiB
Plaintext
Raw Normal View History

2013-12-13 11:39:26 +01:00
2013-12-13 15:04:48 +01:00
> module Language.SQL.SimpleSQL.Syntax
> (ScalarExpr(..)
> ,TypeName(..)
> ,SubQueryExprType(..)
> ,InThing(..)
> ,QueryExpr(..)
2013-12-13 15:04:48 +01:00
> ,makeSelect
> ,Duplicates(..)
> ,Direction(..)
2013-12-13 22:41:12 +01:00
> ,CombineOp(..)
> ,Corresponding(..)
2013-12-13 15:04:48 +01:00
> ,TableRef(..)
> ,JoinType(..)
> ,JoinCondition(..)
> ) where
2013-12-13 11:39:26 +01:00
> data ScalarExpr = NumLit String
> | StringLit String
> | IntervalLit String -- text of interval
> String -- units of interval
> (Maybe Int) -- precision
> | Iden String
> | Iden2 String String
2013-12-13 11:39:26 +01:00
> | Star
> | Star2 String
> | App String [ScalarExpr]
> | AggregateApp String (Maybe Duplicates)
> [ScalarExpr]
> [(ScalarExpr,Direction)]
2013-12-13 22:31:36 +01:00
> | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr,Direction)]
> -- the binop, prefixop and postfix op
> -- are used for symbol and keyword operators
> -- these are used even for the multiple keyword
> -- operators
> | 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
> | Cast ScalarExpr TypeName
> | CastOp TypeName String
> | SubQueryExpr SubQueryExprType QueryExpr
> | In Bool -- true if in, false if not in
> ScalarExpr InThing
2013-12-13 11:39:26 +01:00
> deriving (Eq,Show)
> data TypeName = TypeName String deriving (Eq,Show)
> data InThing = InList [ScalarExpr]
> | InQueryExpr QueryExpr
> deriving (Eq,Show)
> data SubQueryExprType = SqExists | SqSq | SqAll | SqSome | SqAny
> 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
> ,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)
> 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)