Add more methods to map column/property names
This commit is contained in:
parent
a690f8d8df
commit
a014fddd8a
29
lib/sql.js
29
lib/sql.js
|
@ -22,7 +22,11 @@ BaseSQL.prototype.queryOne = function (sql, callback) {
|
|||
};
|
||||
|
||||
BaseSQL.prototype.dataSource = function(model) {
|
||||
return this._models[model].model.schema;
|
||||
var m = this._models[model];
|
||||
if(!m) {
|
||||
console.log(new Error('Model not found: ' + model).stack);
|
||||
}
|
||||
return m.model.schema;
|
||||
}
|
||||
|
||||
BaseSQL.prototype.table = function (model) {
|
||||
|
@ -43,12 +47,27 @@ BaseSQL.prototype.column = function (model, property) {
|
|||
return name;
|
||||
};
|
||||
|
||||
BaseSQL.prototype.propertyName = function (model, column) {
|
||||
var props = this._models[model].properties;
|
||||
for(var p in props) {
|
||||
if(this.column(model, p) === column) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
BaseSQL.prototype.idName = function (model) {
|
||||
return this.dataSource(model).idName(model);
|
||||
};
|
||||
|
||||
BaseSQL.prototype.idColumn = function (model) {
|
||||
return this.dataSource(model).idColumnName(model);
|
||||
var name = this.dataSource(model).idColumnName(model);;
|
||||
var dbName = this.dbName;
|
||||
if(typeof dbName === 'function') {
|
||||
name = dbName(name);
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
BaseSQL.prototype.idColumnEscaped = function (model) {
|
||||
|
@ -56,7 +75,11 @@ BaseSQL.prototype.idColumnEscaped = function (model) {
|
|||
};
|
||||
|
||||
BaseSQL.prototype.id = function (model, prop) {
|
||||
return this._models[model].properties[prop].id;
|
||||
var p = this._models[model].properties[prop];
|
||||
if(!p) {
|
||||
console.log(new Error('Property not found: ' + model +'.' + prop).stack);
|
||||
}
|
||||
return p.id;
|
||||
};
|
||||
|
||||
BaseSQL.prototype.escapeName = function (name) {
|
||||
|
|
Loading…
Reference in New Issue