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

58 lines
1.8 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
> (QueryExpr(..)
> ,makeSelect
> ,ScalarExpr(..)
> ,TableRef(..)
> ,JoinType(..)
> ,JoinCondition(..)
> ) where
2013-12-13 11:39:26 +01:00
> data ScalarExpr = Literal String
> | Identifier String
> | Identifier2 String String
> | Star
> | Star2 String
> | App String [ScalarExpr]
> | Op String [ScalarExpr]
> | Case (Maybe ScalarExpr) -- test value
> [(ScalarExpr,ScalarExpr)] -- when branches
> (Maybe ScalarExpr) -- else value
> | Parens ScalarExpr
> deriving (Eq,Show)
> data QueryExpr
> = Select
> {qeSelectList :: [(Maybe String,ScalarExpr)]
> ,qeFrom :: [TableRef]
> ,qeWhere :: Maybe ScalarExpr
> ,qeGroupBy :: [ScalarExpr]
> ,qeHaving :: Maybe ScalarExpr
> ,qeOrderBy :: [ScalarExpr]
> } deriving (Eq,Show)
> makeSelect :: QueryExpr
> makeSelect = Select {qeSelectList = []
> ,qeFrom = []
> ,qeWhere = Nothing
> ,qeGroupBy = []
> ,qeHaving = Nothing
> ,qeOrderBy = []}
> 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)