UNPKG

dt-sql-parser

Version:

SQL Parsers for BigData, built with antlr4

137 lines (136 loc) 4.34 kB
import { Column_defContext, TableRefContext, } from '../../lib/postgresql/PostgreSqlParser'; import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector'; import { EntityContextType } from '../common/types'; export class PostgreSqlEntityCollector 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: [TableRefContext.name], }, ] : undefined); } exitTableNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.TABLE_CREATE); } exitViewName(ctx) { var _a; const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT; this.pushEntity(ctx, EntityContextType.VIEW, needCollectAttr ? [ { attrName: AttrName.alias, endContextList: [TableRefContext.name], }, ] : undefined); } exitViewNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.VIEW_CREATE); } exitFunctionNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE); } exitColumnNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [ { attrName: AttrName.comment, endContextList: [Column_defContext.name], }, { attrName: AttrName.colType, endContextList: [Column_defContext.name], }, ]); } exitProcedureName(ctx) { this.pushEntity(ctx, EntityContextType.PROCEDURE); } exitProcedureNameCreate(ctx) { this.pushEntity(ctx, EntityContextType.PROCEDURE_CREATE); } /** ===== Statement begin */ enterSingleStatement(ctx) { this.pushStmt(ctx, StmtContextType.COMMON_STMT); } exitSingleStatement(ctx) { this.popStmt(); } enterCreateDatabase(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_DATABASE_STMT); } exitCreateDatabase(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(); } enterCreateForeignTable(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreateForeignTable(ctx) { this.popStmt(); } enterCreatePartitionForeignTable(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT); } exitCreatePartitionForeignTable(ctx) { this.popStmt(); } enterCreateView(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateView(ctx) { this.popStmt(); } enterCreateMaterializedView(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_VIEW_STMT); } exitCreateMaterializedView(ctx) { this.popStmt(); } enterSelectStatement(ctx) { this.pushStmt(ctx, StmtContextType.SELECT_STMT); } exitSelectStatement(ctx) { this.popStmt(); } enterInsertStatement(ctx) { this.pushStmt(ctx, StmtContextType.INSERT_STMT); } exitInsertStatement(ctx) { this.popStmt(); } enterCreateFunctionStmt(ctx) { this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT); } exitCreateFunctionStmt(ctx) { this.popStmt(); } enterAlterTableStmt(ctx) { this.pushStmt(ctx, StmtContextType.ALTER_TABLE_STMT); } exitAlterTableStmt(ctx) { this.popStmt(); } }