UNPKG

dt-sql-parser

Version:

SQL Parsers for BigData, built with antlr4

132 lines (131 loc) 4.08 kB
import { ColumnCreateTableContext, CreateDefinitionContext, CreateFunctionContext, TableSourceContext, } from '../../lib/mysql/MySqlParser'; import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector'; import { EntityContextType } from '../common/types'; export class MySqlEntityCollector extends EntityCollector { /** ====== Entity Begin */ exitDatabaseName(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE); } exitDatabaseNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.DATABASE_CREATE); } exitTableName(ctx) { var _a; const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT; this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr ? [ { attrName: AttrName.alias, endContextList: [TableSourceContext.name], }, ] : undefined); } exitTableNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [ { attrName: AttrName.comment, endContextList: [ColumnCreateTableContext.name], }, ]); } exitViewName(ctx) { this.pushEntity(ctx, EntityContextType.VIEW); } exitViewNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.VIEW_CREATE); } exitFunctionNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateFunctionContext.name], }, ]); } exitColumnNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [ { attrName: AttrName.comment, endContextList: [CreateDefinitionContext.name], }, { attrName: AttrName.colType, endContextList: [CreateDefinitionContext.name], }, ]); } /** ===== Statement begin */ enterSingleStatement(ctx) { this.pushStmt(ctx, StmtContextType.COMMON_STMT); } exitSingleStatement(ctx) { this.popStmt(); } enterQueryCreateTable(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitQueryCreateTable(ctx) { this.popStmt(); } enterColumnCreateTable(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitColumnCreateTable(ctx) { this.popStmt(); } enterCopyCreateTable(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCopyCreateTable(ctx) { this.popStmt(); } enterCreateView(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateView(ctx) { this.popStmt(); } enterSimpleSelect(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitSimpleSelect(ctx) { this.popStmt(); } enterUnionAndLateralSelect(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitUnionAndLateralSelect(ctx) { this.popStmt(); } enterSelectExpression(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitSelectExpression(ctx) { this.popStmt(); } enterInsertStatement(ctx) { this.pushStmt(ctx, StmtContextType.INSERT_STMT); } exitInsertStatement(ctx) { this.popStmt(); } enterCreateDatabase(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT); } exitCreateDatabase(ctx) { this.popStmt(); } enterCreateFunction(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT); } exitCreateFunction(ctx) { this.popStmt(); } enterCreateFunctionLoadable(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT); } exitCreateFunctionLoadable(ctx) { this.popStmt(); } }