import { P_CREATE_TABLE } from '../../../../../typings' ; import { Table } from '../table' ; import { DatabaseModelInterface , TableModelInterface , RuleHandler } from '../typings' ; /**
 * Formatter for P_CREATE_TABLE rule's parsed JSON.
 */ export class CreateTable implements RuleHandler { database ! : DatabaseModelInterface ; param name getTable ( name ) { return this . database . getTable ( name ) ; } /**
     * Get tables from database.
     */ getTables ( ) { return this . database . getTables ( ) ; } param database setDatabase ( database ) { this . database = database ; } param table pushTable ( table ) { this . database . pushTable ( table ) ; } param json handleDef ( json ) { if ( json . id === 'P_CREATE_TABLE' ) { const def = json . def ; if ( def . id === 'P_CREATE_TABLE_COMMON' ) { const table = Table . fromCommonDef ( def , this . database ) ; if ( table ) { this . pushTable ( table ) ; } } else if ( def . id === 'P_CREATE_TABLE_LIKE' ) { const table = Table . fromAlikeDef ( def , this . getTables ( ) ) ; if ( ! table ) { return ; } /**
                 * Through tests it is noticed that foreign keys are
                 * not kept on duplicated table ~ duartealexf.
                 */ table . foreignKeys = [ ] ; if ( table ) { this . pushTable ( table ) ; } } return ; } throw new TypeError ( `Expected P_CREATE_TABLE rule to be handled but received ${ json . id }` ) ; } }