Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the ast node data types. They are very permissive, in that they allow a lot of invalid SQL to be represented. The type checking process should catch all invalid trees, but doesn't quite manage at the moment. Sorry about all the seemingly pointless type synonyms below, they are an artefact of using UUAGC. You can see labels for the fields by looking at the ag source here: https://github.com/JakeWheat/hssqlppp/blob/master/src/Database/HsSqlPpp/Internals/AstInternal.ag
- data Name
- data NameComponent
- nameComponents :: Name -> [NameComponent]
- ncStr :: NameComponent -> String
- data TypeName
- data ScalarExpr
- = NumberLit Annotation String
- | StringLit Annotation String
- | NullLit Annotation
- | BooleanLit Annotation Bool
- | TypedStringLit Annotation TypeName String
- | Interval Annotation String IntervalField (Maybe Int)
- | Extract Annotation ExtractField ScalarExpr
- | PositionalArg Annotation Integer
- | Placeholder Annotation
- | Cast Annotation ScalarExpr TypeName
- | ImplicitCast Annotation ScalarExpr TypeExtra
- | Star Annotation
- | QStar Annotation NameComponent
- | Identifier Annotation Name
- | Case Annotation CaseScalarExprListScalarExprPairList MaybeScalarExpr
- | CaseSimple Annotation ScalarExpr CaseScalarExprListScalarExprPairList MaybeScalarExpr
- | Exists Annotation QueryExpr
- | App Annotation Name ScalarExprList
- | PrefixOp Annotation Name ScalarExpr
- | PostfixOp Annotation Name ScalarExpr
- | BinaryOp Annotation Name ScalarExpr ScalarExpr
- | SpecialOp Annotation Name ScalarExprList
- | AggregateApp Annotation Distinct ScalarExpr ScalarExprDirectionPairList
- | WindowApp Annotation ScalarExpr ScalarExprList ScalarExprDirectionPairList (Maybe FrameClause)
- | InPredicate Annotation ScalarExpr Bool InList
- | LiftApp Annotation Name LiftFlavour ScalarExprList
- | ScalarSubQuery Annotation QueryExpr
- | AntiScalarExpr String
- | Parens Annotation ScalarExpr
- data InList
- data LiftFlavour
- data Direction
- data Distinct
- data CombineType
- data IntervalField
- data ExtractField
- = ExtractCentury
- | ExtractDay
- | ExtractDecade
- | ExtractDow
- | ExtractDoy
- | ExtractEpoch
- | ExtractHour
- | ExtractIsodow
- | ExtractIsoyear
- | ExtractMicroseconds
- | ExtractMillennium
- | ExtractMilliseconds
- | ExtractMinute
- | ExtractMonth
- | ExtractQuarter
- | ExtractSecond
- | ExtractTimezone
- | ExtractTimezoneHour
- | ExtractTimezoneMinute
- | ExtractWeek
- | ExtractYear
- data FrameClause
- data QueryExpr
- = Select { }
- | CombineQueryExpr {
- ann :: Annotation
- cqType :: CombineType
- cqQe0 :: QueryExpr
- cqQe1 :: QueryExpr
- | Values { }
- | WithQueryExpr {
- ann :: Annotation
- withs :: WithQueryList
- withQe :: QueryExpr
- makeSelect :: QueryExpr
- data WithQuery = WithQuery Annotation NameComponent (Maybe [NameComponent]) QueryExpr
- data SelectList = SelectList Annotation SelectItemList
- data SelectItem
- data TableRef
- = Tref Annotation Name
- | FunTref Annotation ScalarExpr
- | SubTref Annotation QueryExpr
- | JoinTref Annotation TableRef Natural JoinType (Maybe JoinHint) TableRef OnExpr
- | TableAlias Annotation NameComponent TableRef
- | FullAlias Annotation NameComponent [NameComponent] TableRef
- | TableRefParens Annotation TableRef
- data JoinExpr
- data JoinType
- = Inner
- | LeftOuter
- | RightOuter
- | FullOuter
- | Cross
- data JoinHint
- data QueryHint
- type OnExpr = Maybe JoinExpr
- data Natural
- data Statement
- = QueryStatement Annotation QueryExpr
- | Insert Annotation Name [NameComponent] QueryExpr MaybeSelectList
- | Update Annotation Name SetClauseList TableRefList MaybeBoolExpr MaybeSelectList
- | Delete Annotation Name TableRefList MaybeBoolExpr MaybeSelectList
- | CopyFrom Annotation Name [NameComponent] CopyFromSource [CopyOption]
- | CopyData Annotation String
- | CopyTo Annotation CopyToSource String [CopyOption]
- | Truncate Annotation [Name] RestartIdentity Cascade
- | CreateTable Annotation Name AttributeDefList ConstraintList MaybeTablePartitionDef
- | AlterTable Annotation Name AlterTableOperation
- | AlterDatabase Annotation Name AlterDatabaseOperation
- | CreateSequence Annotation Name Integer Integer Integer Integer Integer
- | AlterSequence Annotation Name Name
- | CreateTableAs Annotation Name QueryExpr
- | CreateView Annotation Name MaybeNameComponentList QueryExpr
- | AlterView Annotation Name MaybeNameComponentList QueryExpr
- | CreateType Annotation Name TypeAttributeDefList
- | CreateUser Annotation Name String
- | CreateLogin Annotation Name String
- | AlterUser Annotation Name String
- | AlterLogin Annotation Name String
- | CreateFunction Annotation Name ParamDefList TypeName Replace Language FnBody Volatility
- | CreateDomain Annotation Name TypeName String MaybeBoolExpr
- | CreateLanguage Annotation String
- | CreateTrigger Annotation NameComponent TriggerWhen [TriggerEvent] Name TriggerFire Name ScalarExprList
- | DropFunction Annotation IfExists NameTypeNameListPairList Cascade
- | DropSomething Annotation DropType IfExists [Name] Cascade
- | DropTrigger Annotation IfExists NameComponent Name Cascade
- | CreateDatabase Annotation Name
- | Set Annotation String [SetValue]
- | Notify Annotation String
- | Into Annotation Bool [Name] Statement
- | Assignment Annotation Name ScalarExpr
- | Return Annotation MaybeScalarExpr
- | ReturnNext Annotation ScalarExpr
- | ReturnQuery Annotation QueryExpr
- | Raise Annotation RaiseType String ScalarExprList
- | NullStatement Annotation
- | Perform Annotation ScalarExpr
- | Execute Annotation ScalarExpr
- | ForQueryStatement Annotation (Maybe String) NameComponent QueryExpr StatementList
- | ForIntegerStatement Annotation (Maybe String) NameComponent ScalarExpr ScalarExpr StatementList
- | LoopStatement Annotation (Maybe String) StatementList
- | WhileStatement Annotation (Maybe String) ScalarExpr StatementList
- | ContinueStatement Annotation (Maybe String)
- | ExitStatement Annotation (Maybe String)
- | CaseStatementSimple Annotation ScalarExpr ScalarExprListStatementListPairList StatementList
- | CaseStatement Annotation ScalarExprListStatementListPairList StatementList
- | If Annotation ScalarExprStatementListPairList StatementList
- | Block Annotation (Maybe String) VarDefList StatementList
- | AntiStatement String
- | DeclareStatement Annotation [(String, TypeName, Maybe ScalarExpr)]
- | ExecStatement Annotation Name ScalarExprList
- | CreateIndexTSQL Annotation NameComponent Name [NameComponent]
- data CopyToSource
- data CopyFromSource
- data CopyOption
- data SetClause
- data AttributeDef = AttributeDef Annotation NameComponent TypeName MaybeScalarExpr RowConstraintList
- data RowConstraint
- = NullConstraint Annotation String
- | NotNullConstraint Annotation String
- | IdentityConstraint Annotation String (Maybe (Integer, Integer))
- | RowCheckConstraint Annotation String ScalarExpr
- | RowUniqueConstraint Annotation String
- | RowPrimaryKeyConstraint Annotation String
- | RowReferenceConstraint Annotation String Name (Maybe NameComponent) Cascade Cascade
- data Constraint
- data TablePartitionDef = TablePartitionDef Annotation NameComponent Integer TablePartitionDateTimeInterval
- data TablePartitionDateTimeInterval
- data TypeAttributeDef = TypeAttDef Annotation NameComponent TypeName
- data AlterDatabaseOperation = RenameDatabase Annotation Name
- data AlterTableOperation
- data AlterTableAction
- data AlterColumnAction
- data TriggerWhen
- data TriggerEvent
- data TriggerFire
- data DropType
- data Cascade
- data IfExists
- data RestartIdentity
- data Replace
- data Volatility
- data Language
- data FnBody
- data ParamDef
- data VarDef
- data RaiseType
- = RNotice
- | RException
- | RError
- data SetValue
- type WithQueryList = [WithQuery]
- type MaybeSelectList = Maybe SelectList
- type TableRefList = [TableRef]
- type MaybeScalarExpr = Maybe ScalarExpr
- type ScalarExprList = [ScalarExpr]
- type ScalarExprListList = [ScalarExprTransposedList]
- type SetClauseList = [SetClause]
- type AttributeDefList = [AttributeDef]
- type ConstraintList = [Constraint]
- type TypeAttributeDefList = [TypeAttributeDef]
- type ParamDefList = [ParamDef]
- type TypeNameList = [TypeName]
- type NameTypeNameListPair = (Name, TypeNameList)
- type NameTypeNameListPairList = [NameTypeNameListPair]
- type ScalarExprListStatementListPair = (ScalarExprList, StatementList)
- type ScalarExprListStatementListPairList = [ScalarExprListStatementListPair]
- type ScalarExprStatementListPair = (ScalarExpr, StatementList)
- type ScalarExprStatementListPairList = [ScalarExprStatementListPair]
- type VarDefList = [VarDef]
- type SelectItemList = [SelectItem]
- type RowConstraintList = [RowConstraint]
- type CaseScalarExprListScalarExprPair = (ScalarExprList, ScalarExpr)
- type CaseScalarExprListScalarExprPairList = [CaseScalarExprListScalarExprPair]
- type StatementList = [Statement]
- type ScalarExprDirectionPair = (ScalarExpr, Direction)
- type ScalarExprDirectionPairList = [ScalarExprDirectionPair]
- type AlterTableActionList = [AlterTableAction]
- type MaybeNameComponentList = Maybe NameComponentList
- type NameComponentList = [NameComponent]
- type MaybeBoolExpr = Maybe ScalarExpr
Name and TypeName
data NameComponent
nameComponents :: Name -> [NameComponent]
ncStr :: NameComponent -> String
data TypeName
Scalar expressions
data ScalarExpr
data InList
data IntervalField
data ExtractField
data FrameClause
Query expressions
data QueryExpr
Select | |
CombineQueryExpr | |
| |
Values | |
WithQueryExpr | |
|
'default' valued select, use for creating select values
makeSelect :: QueryExpr makeSelect = Select {ann = emptyAnnotation ,selDistinct = All ,selSelectList = (SelectList emptyAnnotation []) ,selTref = [] ,selWhere = Nothing ,selGroupBy = [] ,selHaving = Nothing ,selOrderBy = [] ,selLimit = Nothing ,selOffset = Nothing ,selOption = []}
On its own, it isn't valid syntax: to use it you have to replace the select list at minimum
use something like this
s = makeSelect {selSelectList = sl [se $ i "a"] ,selTref = [tref "t"]} where a = emptyAnnotation sl = SelectList a se = SelExp a i = Identifier a tref t = Tref a (Name a [Nmc t])
data WithQuery
data SelectItem
data TableRef
data JoinExpr
data QueryHint
Statements
data Statement
dml components
data CopyToSource
data CopyFromSource
data CopyOption
data SetClause
ddl components
data AttributeDef
data RowConstraint
data Constraint
data TablePartitionDef
data TypeAttributeDef
data AlterTableOperation
data AlterTableAction
data AlterColumnAction
data TriggerEvent
data RestartIdentity
function ddl components
data FnBody
PlPgsql components
data ParamDef
data VarDef
utility
data SetValue
misc
type WithQueryList = [WithQuery]
type MaybeSelectList = Maybe SelectList
type TableRefList = [TableRef]
type MaybeScalarExpr = Maybe ScalarExpr
type ScalarExprList = [ScalarExpr]
type ScalarExprListList = [ScalarExprTransposedList]
type SetClauseList = [SetClause]
type AttributeDefList = [AttributeDef]
type ConstraintList = [Constraint]
type TypeAttributeDefList = [TypeAttributeDef]
type ParamDefList = [ParamDef]
type TypeNameList = [TypeName]
type NameTypeNameListPair = (Name, TypeNameList)
type VarDefList = [VarDef]
type SelectItemList = [SelectItem]
type RowConstraintList = [RowConstraint]
type StatementList = [Statement]
type ScalarExprDirectionPair = (ScalarExpr, Direction)
type AlterTableActionList = [AlterTableAction]
type NameComponentList = [NameComponent]
type MaybeBoolExpr = Maybe ScalarExpr