sql-ddl-to-json-schema
Version:
Parse and convert SQL DDL statements to a JSON Schema.
59 lines (58 loc) • 2 kB
TypeScript
import { O_CREATE_TABLE_CREATE_DEFINITION, O_ALTER_TABLE_SPEC_ADD_COLUMNS_COLUMN, ColumnInterface } from '../../../../typings';
import { PrimaryKeyModelInterface, ForeignKeyModelInterface, UniqueKeyModelInterface, ColumnModelInterface, DatatypeModelInterface, ColumnReferenceModelInterface, ColumnOptionsModelInterface } from './typings';
/**
* Table column.
*/
export declare class Column implements ColumnModelInterface {
name: string;
type: DatatypeModelInterface;
reference?: ColumnReferenceModelInterface;
options?: ColumnOptionsModelInterface;
/**
* Creates a column from a JSON def.
*
* @param json JSON format parsed from SQL.
*/
static fromDef(json: O_CREATE_TABLE_CREATE_DEFINITION): Column;
/**
* Creates a column from an object containing needed properties.
*
* @param json Object containing properties.
*/
static fromObject(json: O_ALTER_TABLE_SPEC_ADD_COLUMNS_COLUMN): Column;
/**
* JSON casting of this object calls this method.
*/
toJSON(): ColumnInterface;
/**
* Create a deep clone of this model.
*/
clone(): Column;
/**
* Whether this column is primary key.
*/
isPrimaryKey(): boolean;
/**
* Whether this column is unique key.
*/
isUniqueKey(): boolean;
/**
* Whether this column is foreign key.
*/
isForeignKey(): boolean;
/**
* Extracts instance of PrimaryKey if this column is primary key.
* Removes 'primary' property from options.
*/
extractPrimaryKey(): PrimaryKeyModelInterface | undefined;
/**
* Extracts instance of ForeignKey if this column references other table.
* Removes 'reference' property from options.
*/
extractForeignKey(): ForeignKeyModelInterface | undefined;
/**
* Extracts instance of UniqueKey if this column is unique key.
* Removes 'unique' property from options.
*/
extractUniqueKey(): UniqueKeyModelInterface | undefined;
}