UNPKG

ts-db-helper

Version:
109 lines (108 loc) 3.5 kB
import { DbTable } from '../models/structure/db-table.model'; import { DbHelperModel } from '../models/db-helper-model.model'; import { DataModel } from '../models/structure/data-model.model'; /** * @private * @class ModelManager * * @description * This class is a singleton collecting data model * This manager has not to be exposed, it is used to provide DataModel * every time it is necessary * * @author Olivier Margarit * @since 0.1 */ export declare class ModelManager { /** * @static * @public * @property {string} version the current data model version, this is provided by the * module configuration, @see NgDbHelperModuleConfig */ static version: string; /** * @static * @private * @property {ModelManager} instance private reference to the model manager instance */ private static instance; /** * @private * @property {{[index: string]: DbTable}} tables hashmap of table names to their datamodel */ private tables; /** * @private * @property {{[index: string]: string}} models hashmap of model names with theirs linked table name */ private models; /** * @static * @public * @method getInstance methode that return the manager instance * * @return {ModelManager} the unique instance */ static getInstance(): ModelManager; /** * @public * @method addModel this method is part of private API, it is called by * decorator to add new table to model * * @param {DbTable} dbTable newModel model extending DbHelperModel */ addModel(dbTable: DbTable): void; /** * @public * @method getColumnNameForField is a part of the private API * This method is called by column decorators to add field to * the Ddate model tables * * @param {{new(): DbHelperModel}} model model extending DbHelperModel * @param {string} fieldName field to add to the model table * * @return {string} the column name for field "fieldName" of the model "model" */ getColumnNameForField(model: { new (): DbHelperModel; }, fieldName: string): string; /** * @public * @method getDataModel get datamodel for model migrations * * @return {DataModel} data model generated by decorators */ getDataModel(): DataModel; /** * @public * @method getModelCount return the number of model with decorators * This method is used to comput minor version of the DataModel to automigrate * the model. The feature is deactivable from config. * * @return {number} the number of table */ getModelCount(): number; /** * @public * @method getModel this is a private API to get model and use it to build queries * * @param {string | DbHelperModel | {new(): DbHelperModel }} model reference to the model * * @return {DbTable} the table declared for the model */ getModel(model: string | DbHelperModel | { new (): DbHelperModel; }): DbTable; /** * @public * @method getTables return the table name linked to the model * * @param {{new(): DbHelperModel}} model model extending DbHelperModel * * @return {string} table name */ getTable(model: { new (): DbHelperModel; }): string; }