UNPKG

@magic-mustard/sqlsync

Version:

SQLSync simplifies database schema evolution by allowing a declarative approach to table management

46 lines (45 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SqlParser = void 0; const namespace_1 = require("./namespace"); const flags_1 = require("./flags"); const namespace_2 = require("./enums/namespace"); const enum_processor_1 = require("./enums/enum.processor"); const file_processor_1 = require("./files/file.processor"); const namespace_3 = require("./split-statements/namespace"); const split_statement_processor_1 = require("./split-statements/split.statement.processor"); const namespace_4 = require("./tables/namespace"); const table_processor_1 = require("./tables/table.processor"); class SqlParser extends namespace_1.Parser.AbstractProcessor { constructor(filePath, fileContents, migrations, state, contentBetweenFlags) { const file = { path: filePath, contents: fileContents }; super(file, migrations, state, contentBetweenFlags); } process() { const processor = this.getFileType(this.file.contents, this.file.path); processor.process(); } getFileType(content, filePath) { // Validate the flag structure first flags_1.Flags.validateFlagStructure(content, filePath); // Extract the file type const fileType = flags_1.Flags.extractFileTypeFlag(content, filePath); return this.getProcessor(fileType); } getProcessor(fileType) { switch (fileType) { case namespace_3.SplitStatements.FileType: return new split_statement_processor_1.SplitStatementProcessor(this.file, this.migrations, this.state, this.contentBetweenFlags); case namespace_4.Tables.FileType: return new table_processor_1.TableProcessor(this.file, this.migrations, this.state, this.contentBetweenFlags); case namespace_2.Enums.FileType: return new enum_processor_1.EnumProcessor(this.file, this.migrations, this.state, this.contentBetweenFlags); default: return new file_processor_1.FileProcessor(this.file, this.migrations, this.state, this.contentBetweenFlags); } } } exports.SqlParser = SqlParser;