import { P_RENAME_TABLE } from '../../../../../typings' ; import { DatabaseModelInterface , TableModelInterface , RuleHandler } from '../typings' ; /**
 * Formatter for P_RENAME_TABLE rule's parsed JSON.
 */ export class RenameTable implements RuleHandler { database ! : DatabaseModelInterface ; param name getTable ( name ) { return this . database . getTable ( name ) ?? undefined ; } param database setDatabase ( database ) { this . database = database ; } /**
     * Get tables from database.
     */ getTables ( ) { return this . database . getTables ( ) ; } param json handleDef ( json ) { if ( json . id === 'P_RENAME_TABLE' ) { json . def . forEach ( ( def ) => { const table = this . getTables ( ) . find ( ( t ) => t . name === def . table ) ; if ( ! table ) { return ; } table . renameTo ( def . newName ) ; } ) ; return ; } throw new TypeError ( `Expected P_RENAME_TABLE rule to be handled but received ${ json . id }` ) ; } }