UNPKG

sql-ddl-to-json-schema

Version:

Parse and convert SQL DDL statements to a JSON Schema.

64 lines (63 loc) 2.24 kB
import { O_CREATE_TABLE_CREATE_DEFINITION, P_CREATE_INDEX, O_CREATE_TABLE_CREATE_DEFINITION_INDEX, O_ALTER_TABLE_SPEC_ADD_INDEX, IndexInterface } from '../../../../typings'; import { IndexModelInterface, IndexColumnModelInterface, IndexOptionsModelInterface, TableModelInterface, ColumnModelInterface } from './typings'; /** * Table index. */ export declare class Index implements IndexModelInterface { name?: string; indexType?: string; columns: IndexColumnModelInterface[]; options?: IndexOptionsModelInterface; /** * Creates an index from a JSON def. * * @param json JSON format parsed from SQL. */ static fromDef(json: O_CREATE_TABLE_CREATE_DEFINITION | P_CREATE_INDEX): Index; /** * Creates an index from an object containing needed properties. * * @param json Object containing properties. */ static fromObject(json: O_CREATE_TABLE_CREATE_DEFINITION_INDEX | P_CREATE_INDEX['def'] | O_ALTER_TABLE_SPEC_ADD_INDEX): Index; /** * JSON casting of this object calls this method. */ toJSON(): IndexInterface; /** * Create a deep clone of this model. */ clone(): Index; /** * Drops a column from index. Returns whether column was removed. * * @param name Column name to be dropped. */ dropColumn(name: string): boolean; /** * Get the columns in given table which this * index's index columns refer to. * * @param table Table in question. */ getColumnsFromTable(table: TableModelInterface): ColumnModelInterface[]; /** * Whether the given table has all of this index's columns. * * @param table Table in question. */ hasAllColumnsFromTable(table: TableModelInterface): boolean; /** * Set size of this index to the size of index's column in given * table, if the size of this index is not already set. * @param table Table to search size for. */ setIndexSizeFromTable(table: TableModelInterface): void; /** * Rename index column name. * * @param column Column being renamed. * @param newName New column name. */ renameColumn(column: ColumnModelInterface, newName: string): void; }