UNPKG

ts-db-helper

Version:
126 lines 3.79 kB
/** * @public * @class DbColumn * * @description * This class is a column model * to help model migration to do his soup * * @author Olivier Margarit * @since 0.1 */ var DbColumn = /** @class */ (function () { /** * @public * @constructor Create column instance * * @param {string} name column name */ function DbColumn(name) { /** * @public * @property {boolean} primaryKey define the column as primary key of the table, * the default value is false */ this.primaryKey = false; /** * @public * @property {boolean} autoIncrement define if the column value is auto incremented * default value is false */ this.autoIncrement = false; /** * @public * @property {boolean} unique define if column value should be unique. Default value * is false */ this.unique = false; /** * @public * @property {boolean} indexed define if column value should be indexed. Default value * is false */ this.indexed = false; /** * @public * @property {string} type define type of the column, type must be compatible with * the field type plus the sqlite manged type */ this.type = 'string'; /** * @public * @property {string} foreignTable foreign table name */ this.foreignTable = null; /** * @public * @property {string} foreignKey foreign key linked to current key */ this.foreignKey = null; /** * @public * @property {string} foreignField field name of the foreign model */ this.foreignField = null; /** * @public * @property {any} defaultValue the default value of the column */ this.defaultValue = undefined; if (name) { this.name = name; this.field = this.name; } } /** * @public * @method configure configure the column from configurator model * * @param {ColumnConfig} config the configurator object * * @since 0.2 */ DbColumn.prototype.configure = function (config) { if (config.name) { this.name = config.name; } if (config.type) { this.type = config.type; } if (config.primaryKey !== undefined) { this.primaryKey = config.primaryKey; } if (config.unique !== undefined) { this.unique = config.unique; } if (config.indexed !== undefined) { this.indexed = config.indexed; } if (config.autoIncrement !== undefined) { this.autoIncrement = config.autoIncrement; } }; /** * @public * @method fromAlias get aliased column * * @param {string} alias the alias label * * @return {DbColumn} the aliased column * * @since 0.2 */ DbColumn.prototype.fromAlias = function (alias) { var aliasColumn = new DbColumn(alias + '.' + this.name); aliasColumn.field = alias + '.' + this.field; aliasColumn.type = this.type; aliasColumn.primaryKey = this.primaryKey; aliasColumn.unique = this.unique; aliasColumn.indexed = this.indexed; aliasColumn.autoIncrement = this.autoIncrement; return aliasColumn; }; return DbColumn; }()); export { DbColumn }; //# sourceMappingURL=db-column.model.js.map