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(..)
|
|
|
|
> ,QueryExpr(..)
|
2013-12-13 15:04:48 +01:00
|
|
|
> ,makeSelect
|
2013-12-13 17:50:41 +01:00
|
|
|
> ,Duplicates(..)
|
|
|
|
> ,Direction(..)
|
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
|
|
|
|
> | Iden String
|
|
|
|
> | Iden2 String String
|
2013-12-13 11:39:26 +01:00
|
|
|
> | Star
|
|
|
|
> | Star2 String
|
|
|
|
> | App String [ScalarExpr]
|
|
|
|
> | Op String [ScalarExpr]
|
|
|
|
> | 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
|
|
|
|
> | CastOp String TypeName
|
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 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 11:39:26 +01:00
|
|
|
> } deriving (Eq,Show)
|
|
|
|
|
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 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
|
|
|
|
> | JoinAlias TableRef String
|
|
|
|
> | 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)
|