UNPKG

jsonschema2ddl

Version:
156 lines (155 loc) 4.62 kB
interface ColumnParams { name: string; database_flavor?: string; comment?: string; constraints?: any; jsonschema_type?: string; jsonschema_fields?: any; } interface ForeignKeyColumnParams extends ColumnParams { table_ref: Table; } interface TableParams { ref: string; name: string; database_flavor: string; columns?: Column[]; primary_key?: Column; comment?: string; indexes?: string[]; unique_columns?: string[]; jsonschema_fields: any; } interface ExpandColumnsParams { table_definitions?: any; columns_definitions?: any; referenced?: boolean; } /** * Object to encapsulate a Column. * * Attributes: * name(str): name of the Column. * database_flavor(str): postgres or redshift.Defaults to postgres. * comment(str): comment of the Column.Defaults to None. * constraints(Dict): other columns constraints (not implemented). * jsonschema_fields(Dict): Original fields in the jsonschema. */ export declare class Column { name: string; database_flavor: string; comment: string; constraints: any; jsonschema_type: string; jsonschema_fields: any; constructor({ name, database_flavor, comment, constraints, jsonschema_type, jsonschema_fields }: ColumnParams); get max_length(): number; /** * Data type of the columns. * * It accounts of the mapping of the original type to the db types. * * Returns: * str: data type of the column. */ get data_type(): string; get is_pk(): boolean; /** * Returns true if the column is a index. * * Returns: * bool: True if it is index. */ get is_index(): boolean; /** * Returns true if the column is a unique. * * Returns: * bool: True if it is unique. */ get is_unique(): boolean; /** * Returns true if the column is a foreign key. * * Returns: * bool: True if it is foreign key */ get is_fk(): boolean; hash(): string; toString(): string; } /** * Object to encapsulate a Table. * * Attributes: * ref(str): id or reference to the table in the jsonschema. * name(str): name of the table. * database_flavor(str): postgres or redshift.Defaults to postgres. * columns(List[Column]): columns of the table. * primary_key(Column): Primary key column of the table. * comment(str): comment of the table.Defaults to None. * indexes(List[str]): Table indexeses(not implemented). * unique_columns(List[str]): Table unique constraints(not implemented). * jsonschema_fields(Dict): Original fields in the jsonschema. */ export declare class Table { ref: string; name: string; database_flavor: string; columns: Column[]; jsonschema_fields: any; primary_key?: Column; comment?: string; indexes?: string[]; unique_columns?: string[]; constructor({ ref, name, database_flavor, columns, primary_key, comment, indexes, unique_columns, jsonschema_fields }: TableParams); private _expanded; /** * Expand the columns definitions of the * * Args: * table_definitions(Dict, optional): Dictionary with the rest of the * tables definitions.It is used for recursive calls to get the * foreign keys.Defaults to dict(). * columns_definitions(Dict, optional): Dictionary with the definition * of columns outside the main properties field.Defaults to dict(). * referenced(bool, optional): Whether or not the table is referenced * by others.Used to make sure there is a Primary Key defined. * Defaults to False. * * @param table_definitions * @param columns_definitions * @param referenced * @returns */ expand_columns({ table_definitions, columns_definitions, referenced }: ExpandColumnsParams): this; _deduplicate_columns(columns: Column[]): Column[]; } /** * Special type of Column object to represent a foreign key * * Attributes: * table_ref(Table): Pointer to the foreign table object */ export declare class FKColumn extends Column { table_ref: Table; constructor(params: ForeignKeyColumnParams); /** * Data type of the foreign key. * * Accounts of the data type of the primary key of the foreing table. * * Returns: * str: the column data type. */ get data_type(): string; /** * Returns true if the column is a foreign key. * * Returns: * bool: True if it is foreign key. */ get is_fk(): boolean; toString(): string; } export {};