rawsql-ts
Version:
High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
149 lines (148 loc) • 5.84 kB
TypeScript
export declare enum SqlPrintTokenType {
container = 0,
keyword = 1,
value = 2,// Represents non-keyword elements such as table names
comma = 3,// Represents comma ','
parenthesis = 4,// Represents parentheses: ( ) { } [ ]
operator = 5,// Represents operators such as +, -, *, /
comment = 6,// SQL comments /* */ or --
parameter = 7,
dot = 8,
type = 9,
space = 10,// Whitespace characters
argumentSplitter = 11,
commentNewline = 12
}
export declare enum SqlPrintTokenContainerType {
ColumnReference = "ColumnReference",
LiteralValue = "LiteralValue",
IdentifierString = "IdentifierString",
InlineQuery = "InlineQuery",
StringSpecifierExpression = "StringSpecifierExpression",
None = "",
ValueList = "ValueList",
OrderByItem = "OrderByItem",
FunctionCall = "FunctionCall",
UnaryExpression = "UnaryExpression",
BinaryExpression = "BinaryExpression",
SwitchCaseArgument = "SwitchCaseArgument",
ElseClause = "ElseClause",
CaseKeyValuePair = "CaseKeyValuePair",
CaseThenValue = "CaseThenValue",
CaseElseValue = "CaseElseValue",
ParenExpression = "ParenExpression",
CastExpression = "CastExpression",
CaseExpression = "CaseExpression",
ArrayExpression = "ArrayExpression",
BetweenExpression = "BetweenExpression",
TypeValue = "TypeValue",
TupleExpression = "TupleExpression",
WindowFrameExpression = "WindowFrameExpression",
SelectItem = "SelectItem",
SelectClause = "SelectClause",
DistinctOn = "DistinctOn",
SourceExpression = "SourceExpression",
FromClause = "FromClause",
JoinClause = "JoinClause",
JoinOnClause = "JoinOnClause",
JoinUsingClause = "JoinUsingClause",
FunctionSource = "FunctionSource",
SourceAliasExpression = "SourceAliasExpression",
RawString = "RawString",
QualifiedName = "QualifiedName",
WhereClause = "WhereClause",
SimpleSelectQuery = "SimpleSelectQuery",
OrderByClause = "OrderByClause",
GroupByClause = "GroupByClause",
HavingClause = "HavingClause",
SubQuerySource = "SubQuerySource",
PartitionByClause = "PartitionByClause",
WindowFrameClause = "WindowFrameClause",
LimitClause = "LimitClause",
OffsetClause = "OffsetClause",
ForClause = "ForClause",
WindowClause = "WindowClause",
BinarySelectQueryOperator = "BinarySelectQueryOperator",
Values = "Values",
ValuesQuery = "ValuesQuery",
WithClause = "WithClause",
CommonTable = "CommonTable",
WindowFrameSpec = "WindowFrameSpec",
WindowFrameBoundStatic = "WindowFrameBoundStatic",
WindowFrameBoundaryValue = "WindowFrameBoundaryValue",
FetchClause = "FetchClause",
FetchExpression = "FetchExpression",
InsertQuery = "InsertQuery",
InsertClause = "InsertClause",
UpdateQuery = "UpdateQuery",
UpdateClause = "UpdateClause",
DeleteQuery = "DeleteQuery",
DeleteClause = "DeleteClause",
UsingClause = "UsingClause",
ReturningClause = "ReturningClause",
SetClause = "SetClause",
SetClauseItem = "SetClauseItem",
CreateTableQuery = "CreateTableQuery",
CreateTableDefinition = "CreateTableDefinition",
TableColumnDefinition = "TableColumnDefinition",
ColumnConstraintDefinition = "ColumnConstraintDefinition",
TableConstraintDefinition = "TableConstraintDefinition",
ReferenceDefinition = "ReferenceDefinition",
CreateIndexStatement = "CreateIndexStatement",
IndexColumnList = "IndexColumnList",
IndexColumnDefinition = "IndexColumnDefinition",
CreateSequenceStatement = "CreateSequenceStatement",
AlterSequenceStatement = "AlterSequenceStatement",
SequenceOptionList = "SequenceOptionList",
SequenceOptionClause = "SequenceOptionClause",
DropTableStatement = "DropTableStatement",
DropIndexStatement = "DropIndexStatement",
AlterTableStatement = "AlterTableStatement",
AlterTableAddConstraint = "AlterTableAddConstraint",
AlterTableDropConstraint = "AlterTableDropConstraint",
AlterTableAddColumn = "AlterTableAddColumn",
AlterTableDropColumn = "AlterTableDropColumn",
AlterTableAlterColumnDefault = "AlterTableAlterColumnDefault",
DropConstraintStatement = "DropConstraintStatement",
ExplainStatement = "ExplainStatement",
ExplainOption = "ExplainOption",
AnalyzeStatement = "AnalyzeStatement",
MergeQuery = "MergeQuery",
MergeWhenClause = "MergeWhenClause",
MergeUpdateAction = "MergeUpdateAction",
MergeDeleteAction = "MergeDeleteAction",
MergeInsertAction = "MergeInsertAction",
MergeDoNothingAction = "MergeDoNothingAction",
CommentBlock = "CommentBlock"
}
export declare class SqlPrintToken {
/**
* The type of this token, representing the general category (e.g. keyword, value, operator).
*/
type: SqlPrintTokenType;
/**
* The actual text content of this token, following SQL syntax.
*/
text: string;
/**
* The type of the container this token belongs to. Used for clauses, functions, or other groupings.
*/
containerType: SqlPrintTokenContainerType;
/**
* Optional. Keywords that are part of this token, like DISTINCT in a SELECT clause.
* These should typically be processed before innerTokens.
*/
keywordTokens?: SqlPrintToken[];
/**
* Child tokens that belong to this container.
*/
innerTokens: SqlPrintToken[];
/**
* Optional marker indicating that this token originated from headerComments.
* This flag is only valid for CommentBlock containers and used by printers
* to selectively emit only header-level annotations.
*/
isHeaderComment?: boolean;
constructor(type: SqlPrintTokenType, text?: string, containerType?: SqlPrintTokenContainerType);
markAsHeaderComment(): void;
}