Skip to content

Commit

Permalink
Fixed rawExpression on QueryBuilder. Removed paramify of RawExpressions
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jun 29, 2018
1 parent f09cd64 commit d2527db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions lib/client/database/database-query.js
Expand Up @@ -2,10 +2,16 @@
"use strict";


const Statement = require('../../db/statement');
const RID = require('../../recordid');
const Query = require('../../db/query');
const Promise = require('bluebird');
const utils = require('../../utils');

const RawExpression = Statement.RawExpression;




class SessionQuery extends Query {

Expand Down Expand Up @@ -423,6 +429,44 @@ class SessionQuery extends Query {
}
return statement.join(' ');
}

_objectToSet(obj) {
var expressions = [],
params = {},
keys = Object.keys(obj),
total = keys.length,
key,
i,
paramName,
value;
for (i = 0; i < total; i++) {
key = keys[i];
value = obj[key];
if (typeof value === "function") {
var child = new Statement(this.db);
child._state.paramIndex = this._state.paramIndex;
value(child);
expressions.push(key + " = (" + child.toString() + ")");
} else if (value instanceof Statement) {
expressions.push(key + " = (" + value.toString() + ")");
} else if (value instanceof RID) {
expressions.push(key + " = " + value);
} else if (value instanceof RawExpression) {
expressions.push(key + " = " + utils.encode(value));
this.addParam(paramName, value);
} else if (value !== undefined) {
paramName = "param" + paramify(key) + this._state.paramIndex++;
expressions.push(key + " = :" + paramName);
this.addParam(paramName, value);
}
}

if (expressions.length === 0) {
return false;
} else {
return expressions.join(", ");
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion test/database/database-query-test.js
Expand Up @@ -380,7 +380,7 @@ describe("ODatabase API - Query", function () {
uuid: this.db.rawExpression("format('%s',uuid())")
}).one()
.then(function (user) {
user.uuid.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
user.uuid.should.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
});
});
});
Expand Down

0 comments on commit d2527db

Please sign in to comment.