sql-ddl-to-json-schema
Version:
Parse and convert SQL DDL statements to a JSON Schema.
64 lines (63 loc) • 2.23 kB
TypeScript
import { O_ALTER_TABLE_SPEC_ADD_PRIMARY_KEY, O_CREATE_TABLE_CREATE_DEFINITION, O_CREATE_TABLE_CREATE_DEFINITION_PRIMARY_KEY, PrimaryKeyInterface } from '../../../../typings';
import { PrimaryKeyModelInterface, IndexColumnModelInterface, IndexOptionsModelInterface, TableModelInterface, ColumnModelInterface } from './typings';
/**
* Primary key of a table.
*/
export declare class PrimaryKey implements PrimaryKeyModelInterface {
name?: string;
indexType?: string;
columns?: IndexColumnModelInterface[];
options?: IndexOptionsModelInterface;
/**
* Creates a primary key from a JSON def.
*
* @param json JSON format parsed from SQL.
*/
static fromDef(json: O_CREATE_TABLE_CREATE_DEFINITION): PrimaryKey;
/**
* Creates a primary key from an object containing needed properties.
*
* @param json Object containing properties.
*/
static fromObject(json: O_ALTER_TABLE_SPEC_ADD_PRIMARY_KEY | O_CREATE_TABLE_CREATE_DEFINITION_PRIMARY_KEY): PrimaryKey;
/**
* JSON casting of this object calls this method.
*/
toJSON(): PrimaryKeyInterface;
/**
* Create a deep clone of this model.
*/
clone(): PrimaryKey;
/**
* Pushes an index column to this primary key.
*
* @param {IndexColumn} indexColumn Index column to be pushed.
*/
pushColumn(indexColumn: IndexColumnModelInterface): void;
/**
* Drops a column from key. Returns whether column was removed.
*
* @param name Column name to be dropped.
*/
dropColumn(name: string): boolean;
/**
* Get the columns in given table which this
* primary key's index columns refer to.
*
* @param table Table in question.
*/
getColumnsFromTable(table: TableModelInterface): ColumnModelInterface[];
/**
* Whether the given table has all of this primary key's columns.
*
* @param table Table in question.
*/
hasAllColumnsFromTable(table: TableModelInterface): boolean;
/**
* Rename index column name.
*
* @param column Column being renamed.
* @param newName New column name.
*/
renameColumn(column: ColumnModelInterface, newName: string): void;
}