UNPKG

ts-db-helper

Version:
132 lines (131 loc) 4.02 kB
import { DbHelperModel } from '../db-helper-model.model'; import { DbRelationModel } from './db-relation.model'; import { TableConfig } from '../../decorators/configurator/table.configurator'; import { DbColumn } from './db-column.model'; /** * @public * @class DbTable * * @description * This class is a table model to help model migration to do his soup * * @author Olivier Margarit * @since 0.1 */ export declare class DbTable { /** * @private * @static * @constant {string} RELATIONS_DEFAULT_KEY the default relation key */ private static readonly RELATIONS_DEFAULT_KEY; /** * @public * @property {string} name cannot be an option information and is the table * name in database */ name: string; /** * @public * @property {number} version, the table model version, information to help migration */ version?: number | undefined; /** * @public * @property {Array<DbColumn>} columnList is an array of DbColumn listing each column * sql properties */ columnList: DbColumn[]; /** * @public * @property {{[index: string]: DbColumn}} column key/value column list with column name as key */ columns: { [index: string]: DbColumn; }; /** * @public * @property {{[index: string]: DbColumn}} fields key/value column list with field name as key */ fields: { [index: string]: DbColumn; }; /** * @public * @property {string} modelName the model name */ modelName: string; /** * @public * @property {{[index: string]: {[index: string]: DbRelationModel}}} relations two dimensional relation access by * model name and relation key */ relations: { [index: string]: { [index: string]: DbRelationModel; }; }; /** * @public * @method configure methode to configure table from configurator object * * @param {TableConfig} config the configurator * * @since 0.2 */ configure(config: TableConfig): void; /** * @public * @method hasAutoIncrementedPrimaryKey check if table has auto increment column * * @return {boolean} true if table has auto increment column * * @since 0.2 */ hasAutoIncrementedPrimaryKey(): boolean; /** * @public * @method hasNoPrimaryKey check if table has no primary key * * @return {boolean} return true if table has no primary key * * @since 0.2 */ hasNoPrimaryKey(): boolean; /** * @public * @method getPrimaryColumns get column playing primary role among table's columns * * @return {Array<DbColumn>} the structured primary column list * * @since 0.2 */ getPrimaryColumns(): DbColumn[]; /** * @public * @method addRelation add relation to table model * * @param {{new(): DbHelperModel}} model the target model of the relation * @param {DbRalationModel} relation the relation * @param {string} key optional key to manage multiple relations to the same model * * @since 0.2 */ addRelation(model: { new (): DbHelperModel; }, relation: DbRelationModel, key?: string): void; /** * @public * @method getRelation get relation from the targetted model and the optionale relation key * * @param {{new(): DbHelperModel}} model the target model of the relation * @param {string} key optional key to manage multiple relations to the same model * * @return {DbRelationModel} the relation matching to the properties, return is null if no relation matches * * @since 0.2 */ getRelation(model: { new (): DbHelperModel; }, key?: string): DbRelationModel | null; }