Update column type info

This commit is contained in:
Raymond Feng 2013-05-29 10:03:01 -07:00
parent 6255da2ae0
commit d9998d8294
3 changed files with 45 additions and 7 deletions

View File

@ -563,6 +563,24 @@ DataSource.prototype.columnName = function (modelName, propertyName) {
}
};
/**
* Return column metadata for specified modelName and propertyName
* @param modelName
* @param propertyName
* @returns {Object} column metadata
*/
DataSource.prototype.columnMetadata = function (modelName, propertyName) {
if(!propertyName) {
return propertyName;
}
var property = this.definitions[modelName].properties[propertyName];
if(property && property[this.adapter.name]) {
return property[this.adapter.name];
} else {
return null;
}
};
/**
* Return column names for specified modelName
* @param modelName

View File

@ -1,15 +1,25 @@
var util = require('util');
/**
*
* @param newClass
* @param baseClass
*/
exports.inherits = function (newClass, baseClass) {
Object.keys(baseClass).forEach(function (classProp) {
newClass[classProp] = baseClass[classProp];
});
Object.keys(baseClass.prototype).forEach(function (instanceProp) {
newClass.prototype[instanceProp] = baseClass.prototype[instanceProp];
});
exports.inherits = function (newClass, baseClass, options) {
util.inherits(newClass, baseClass);
options = options || {
staticProperties: true,
override: false
};
if (options.staticProperties) {
Object.keys(baseClass).forEach(function (classProp) {
if (classProp !== 'super_' && (!newClass.hasOwnProperty(classProp) || options.override)) {
var pd = Object.getOwnPropertyDescriptor(baseClass, classProp);
Object.defineProperty(newClass, classProp, pd);
}
});
}
};

View File

@ -63,6 +63,16 @@ BaseSQL.prototype.column = function (model, property) {
return name;
};
/**
* Get the column name for given model property
* @param model The model name
* @param property The property name
* @returns {Object} The column metadata
*/
BaseSQL.prototype.columnMetadata = function (model, property) {
return this.dataSource(model).columnMetadata(model, property);
};
/**
* Get the corresponding property name for a given column name
* @param model The model name