UNPKG

sql-ddl-to-json-schema

Version:

Parse and convert SQL DDL statements to a JSON Schema.

50 lines (49 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DropIndex = void 0; /** * Formatter for P_DROP_INDEX rule's parsed JSON. */ class DropIndex { database; /** * Get table with given name. * * @param name Table name. */ getTable(name) { return this.database.getTable(name); } /** * Setter for database. * * @param database Database instance. */ setDatabase(database) { this.database = database; } /** * Drops one of the indexes in a table. * * @param json JSON format parsed from SQL. */ handleDef(json) { if (json.id === 'P_DROP_INDEX') { const table = this.getTable(json.def.table); if (!table) { // throw new Error(`Found "DROP INDEX" statement for an unexisting table ${json.def.table}`); return; } const index = table.getIndexByName(json.def.index); if (!index) { // throw new Error(`Found "DROP INDEX" statement for an // unexisting index ${json.def.index} in table ${json.def.table}`); return; } table.dropIndexByInstance(index); return; } throw new TypeError(`Expected P_DROP_INDEX rule to be handled but received ${json.id}`); } } exports.DropIndex = DropIndex;