sql-ddl-to-json-schema
Version:
Parse and convert SQL DDL statements to a JSON Schema.
95 lines (94 loc) • 3.46 kB
TypeScript
import { O_CREATE_TABLE_CREATE_DEFINITION, O_CREATE_TABLE_CREATE_DEFINITION_FOREIGN_KEY, ForeignKeyInterface } from '../../../../typings';
import { ForeignKeyModelInterface, IndexColumnModelInterface, ColumnReferenceModelInterface, ColumnModelInterface, TableModelInterface } from './typings';
/**
* Foreign key of a table.
*/
export declare class ForeignKey implements ForeignKeyModelInterface {
name?: string;
columns: IndexColumnModelInterface[];
reference: ColumnReferenceModelInterface;
/**
* Creates a foreign key from a JSON def.
*
* @param json JSON format parsed from SQL.
*/
static fromDef(json: O_CREATE_TABLE_CREATE_DEFINITION): ForeignKey;
/**
* Creates a foreign key from an object containing needed properties.
*
* @param json Object containing properties.
*/
static fromObject(json: O_CREATE_TABLE_CREATE_DEFINITION_FOREIGN_KEY): ForeignKey;
/**
* JSON casting of this object calls this method.
*/
toJSON(): ForeignKeyInterface;
/**
* Create a deep clone of this model.
*/
clone(): ForeignKey;
/**
* Push an index column to columns array.
*
* @param indexColumn Index column to be pushed.
*/
pushColumn(indexColumn: IndexColumnModelInterface): void;
/**
* Drops an index column, returning a boolean to whether column was removed.
*
* @param name Column name to be dropped.
*/
dropColumn(name: string): boolean;
/**
* Get the columns in given table which this foreign key's index columns refer to.
*
* @param table Table in question.
*/
getColumnsFromTable(table: TableModelInterface): ColumnModelInterface[];
/**
* Get whether the given table has all of this foreign key's owner table columns.
*/
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.
*/
setIndexSizeFromTable(table: TableModelInterface): void;
/**
* Get whether the given table has all of this foreign key's referenced table columns.
*/
hasAllColumnsFromRefTable(table: TableModelInterface): boolean;
/**
* Get referenced table by this foreign key, from array
* of given tables. Returns null if no table was found.
*
* @param tables Table array to search.
*/
getReferencedTable(tables: TableModelInterface[]): TableModelInterface | undefined;
/**
* Checks and returns whether this foreign key references given table and column.
*
* @param table Table to be checked whether there is reference to.
* @param column Column to be checked in given table.
*/
referencesTableAndColumn(table: TableModelInterface, column: ColumnModelInterface): boolean;
/**
* Checks and returns whether this foreign key references given table.
*
* @param table Table to be checked whether there is reference to.
*/
referencesTable(table: TableModelInterface): boolean;
/**
* Rename index column name.
*
* @param column Column being renamed.
* @param newName New column name.
*/
renameColumn(column: ColumnModelInterface, newName: string): void;
/**
* Update referenced table name.
*
* @param newName New table name.
*/
updateReferencedTableName(newName: string): void;
}