diff --git a/lib/sql/Select.js b/lib/sql/Select.js index 63d771ea..6e4068a8 100644 --- a/lib/sql/Select.js +++ b/lib/sql/Select.js @@ -30,10 +30,11 @@ Builder.prototype.table = function (table) { }; Builder.prototype.where = function (field, value, comparison) { - if (!Array.isArray(value) && typeof(value) === 'object') { - comparison = value.op || value.operator || value.comp || value.comparison; - value = value.value; - } + // stand by for now.. + // if (!Array.isArray(value) && typeof(value) === 'object') { + // comparison = value.op || value.operator || value.comp || value.comparison; + // value = value.value; + // } this.opts.where.push({ field : field, value : value, @@ -118,6 +119,41 @@ Builder.prototype.build = function () { // where lst = []; for (i = 0; i < this.opts.where.length; i++) { + if (typeof this.opts.where[i].value.orm_special_object == "function") { + var op = this.opts.where[i].value.orm_special_object(); + switch (op) { + case "between": + lst.push([ + this.escapeId(this.opts.where[i].field), + "BETWEEN", + this.escape(this.opts.where[i].value.from), + "AND", + this.escape(this.opts.where[i].value.to) + ].join(" ")); + break; + case "eq": + case "ne": + case "gt": + case "gte": + case "lt": + case "lte": + switch (op) { + case "eq" : op = "="; break; + case "ne" : op = "<>"; break; + case "gt" : op = ">"; break; + case "gte" : op = ">="; break; + case "lt" : op = "<"; break; + case "lte" : op = "<="; break; + } + lst.push([ + this.escapeId(this.opts.where[i].field), + op, + this.escape(this.opts.where[i].value.val) + ].join(" ")); + break; + } + continue; + } lst.push([ this.escapeId(this.opts.where[i].field), this.opts.where[i].comp, diff --git a/test/integration/test-find-where.js b/test/integration/test-find-where.js index d1f1563c..f54bbdef 100644 --- a/test/integration/test-find-where.js +++ b/test/integration/test-find-where.js @@ -12,7 +12,7 @@ common.createConnection(function (err, db) { var TestModel = db.define(tableName, common.getModelProperties()); - TestModel.find({ id: { value: 1, comparison: '<>' }}, function (err, Instances) { + TestModel.find({ id: common.ORM.ne(1) }, function (err, Instances) { assert.equal(err, null); assert.equal(Array.isArray(Instances), true); assert.equal(Instances[0].id, 2);