Permalink
Browse files

fixed delete column name mapping

  • Loading branch information...
joeferner committed Oct 26, 2012
1 parent 23dce93 commit ec2c32b477297f4c221cc0e22b60259dd253fc6c
Showing with 28 additions and 22 deletions.
  1. +28 −22 lib/driver.js
View
@@ -6,18 +6,18 @@ var util = require('util');
var Class = require('./class');
var Driver = Class.extend({
- init: function () {
+ init: function() {
},
- connect: function (opts, callback) {
+ connect: function(opts, callback) {
throw new Error("Not Implemented");
},
- getValuesSubstitutionString: function (index) {
+ getValuesSubstitutionString: function(index) {
return '?';
},
- getInsertSql: function (obj) {
+ getInsertSql: function(obj) {
var columnNamesSql = [];
var valuesSql = [];
var values = [];
@@ -40,7 +40,7 @@ var Driver = Class.extend({
return result;
},
- getManyToManyInsertSql: function (association, obj, relatedObj) {
+ getManyToManyInsertSql: function(association, obj, relatedObj) {
var valueSubstitutionIndex = 1;
var columnNamesSql = [ association.foreignKey, association.manyToManyForeignKey ];
var valuesSql = [
@@ -57,7 +57,7 @@ var Driver = Class.extend({
return result;
},
- getUpdateSql: function (obj) {
+ getUpdateSql: function(obj) {
var valueSubstitutionIndex = 1;
var columnNamesSql = [];
var values = [];
@@ -80,7 +80,7 @@ var Driver = Class.extend({
return { sql: sql, values: values };
},
- getUpdatePartialSql: function (model, id, data) {
+ getUpdatePartialSql: function(model, id, data) {
var valueSubstitutionIndex = 1;
var columnNamesSql = [];
var values = [];
@@ -122,16 +122,16 @@ var Driver = Class.extend({
return results;
},
- getColumnName: function (column, aliasTables) {
+ getColumnName: function(column, aliasTables) {
var name = column.dbColumnName;
if (aliasTables) {
name = column.tableAlias + '.' + name;
}
return name;
},
- propertyNamesToColumnNames: function (sqlTree, expr) {
- return expr.replace(/([a-zA-Z_\.]+)/g, function (m) {
+ propertyNamesToColumnNames: function(sqlTree, expr, aliasTables) {
+ return expr.replace(/([a-zA-Z_\.]+)/g, function(m) {
var parts = m.split('.');
var partIndex = 0;
if (sqlTree.model && sqlTree.model.columns) {
@@ -144,13 +144,21 @@ var Driver = Class.extend({
var column = sqlTree.findColumnByModelNameAndColumnName(model.modelName, parts[partIndex]);
if (column) {
- return column.tableAlias + '.' + column.dbColumnName;
+ if (aliasTables) {
+ return column.tableAlias + '.' + column.dbColumnName;
+ } else {
+ return column.dbColumnName;
+ }
}
// fall back and try to lookup by name
column = sqlTree.model.columns[m];
if (column) {
- return sqlTree.tableAlias + '.' + column.dbColumnName;
+ if (aliasTables) {
+ return sqlTree.tableAlias + '.' + column.dbColumnName;
+ } else {
+ return column.dbColumnName;
+ }
}
}
@@ -159,20 +167,20 @@ var Driver = Class.extend({
});
},
- getTableAliasSql: function (tableName, alias) {
+ getTableAliasSql: function(tableName, alias) {
return tableName + " AS " + alias;
},
- _updateSubstitutes: function (sql, params) {
+ _updateSubstitutes: function(sql, params) {
var self = this;
var index = 1;
- sql = sql.replace(/\?/g, function () {
+ sql = sql.replace(/\?/g, function() {
return self.getValuesSubstitutionString(index++);
});
return sql;
},
- getSqlFromSqlTree: function (sqlTree) {
+ getSqlFromSqlTree: function(sqlTree) {
var self = this;
var sql = '';
var values = [];
@@ -233,15 +241,13 @@ var Driver = Class.extend({
// process where
var expressions = [];
- var getValuesSubstitutionStringFunc = function (match) {
+ var getValuesSubstitutionStringFunc = function(match) {
return self.getValuesSubstitutionString(valueSubstitutionIndex++);
};
for (i = 0; i < sqlTree.where.length; i++) {
var item = sqlTree.where[i];
var expr = item.expr;
- if (aliasTables) {
- expr = this.propertyNamesToColumnNames(sqlTree, item.expr);
- }
+ expr = this.propertyNamesToColumnNames(sqlTree, item.expr, aliasTables);
expr = expr.replace(/\?/, getValuesSubstitutionStringFunc);
expressions.push(expr);
values = values.concat(item.params);
@@ -282,7 +288,7 @@ var Driver = Class.extend({
return result;
},
- addColumnsSql: function (sql, sqlTree, aliasTables) {
+ addColumnsSql: function(sql, sqlTree, aliasTables) {
var columns = [];
var i;
for (i = 0; i < sqlTree.columns.length; i++) {
@@ -293,7 +299,7 @@ var Driver = Class.extend({
return sql;
},
- addLimitClause: function (sql, sqlTree) {
+ addLimitClause: function(sql, sqlTree) {
if (sqlTree.limitCount) {
sql += 'LIMIT ' + sqlTree.limitCount;
if (sqlTree.limitOffset) {

0 comments on commit ec2c32b

Please sign in to comment.