MCPcopy Create free account
hub / github.com/dresende/node-orm2 / convertToDBVal

Function convertToDBVal

lib/Drivers/DML/mongodb.js:404–442  ·  view source on GitHub ↗
(key, value, timezone)

Source from the content-addressed store, hash-verified

402}
403
404function convertToDBVal(key, value, timezone) {
405 if (value && typeof value.sql_comparator == "function") {
406 var val = (key != "_id" ? value.val : new mongodb.ObjectID(value.val));
407 var comp = value.sql_comparator();
408 var condition = {};
409
410 switch (comp) {
411 case "gt":
412 case "gte":
413 case "lt":
414 case "lte":
415 case "ne":
416 condition["$" + comp] = val;
417 break;
418 case "eq":
419 condition = val;
420 break;
421 case "between":
422 condition["$min"] = value.from;
423 condition["$max"] = value.to;
424 break;
425 case "like":
426 condition["$regex"] = value.expr.replace("%", ".*");
427 break;
428 }
429
430 return condition;
431 }
432
433 if (Buffer.isBuffer(value)) {
434 return new mongodb.Binary(value);
435 }
436
437 if (key == "_id" && typeof value == "string") {
438 value = new mongodb.ObjectID(value);
439 }
440
441 return value;
442}
443
444['ping', 'find', 'count', 'insert', 'update', 'remove', 'clear',].forEach(function (fnName) {
445 Driver.prototype[fnName + 'Async'] = Promise.promisify(Driver.prototype[fnName]);

Callers 1

convertToDBFunction · 0.85

Calls 1

sql_comparatorMethod · 0.80

Tested by

no test coverage detected