forked from dresende/node-orm2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Array property type; added support for non-ObjectID…
… _ids on MongoDB driver
- Loading branch information
1 parent
b6a5b2c
commit 3d7ff3f
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,9 +325,11 @@ Driver.prototype.hasMany = function (Model, association) { | |
}; | ||
|
||
Driver.prototype.update = function (table, changes, conditions, cb) { | ||
convertToDB(changes, this.config.timezone); | ||
convertToDBTypes(changes, this.config.timezone); | ||
convertToDB(conditions, this.config.timezone); | ||
|
||
debugger; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rafaelkaufmann
Author
Owner
|
||
|
||
return this.db.collection(table).update( | ||
conditions, | ||
{ | ||
|
@@ -366,6 +368,12 @@ function convertToDB(obj, timeZone) { | |
} | ||
} | ||
|
||
function convertToDBTypes(obj, timeZone) { | ||
for (var k in obj) { | ||
obj[k] = convertToDBType(k, obj[k], timeZone); | ||
} | ||
} | ||
|
||
function convertFromDB(obj, timezone) { | ||
for (var k in obj) { | ||
if (obj[k] instanceof mongodb.ObjectID) { | ||
|
@@ -379,9 +387,22 @@ function convertFromDB(obj, timezone) { | |
} | ||
} | ||
|
||
function convertToID(value) { | ||
if (value != null && 'number' != typeof value && (value.length != 12 && value.length != 24)) { | ||
return value; | ||
} else { | ||
return mongodb.ObjectID(value); | ||
} | ||
} | ||
|
||
function convertToDBVal(key, value, timezone) { | ||
if (value && typeof value.sql_comparator == "function") { | ||
var val = (key != "_id" ? value.val : new mongodb.ObjectID(value.val)); | ||
var val; | ||
if (key == "_id") { | ||
val = convertToID(value.val); | ||
} else { | ||
val = value.val; | ||
} | ||
var comp = value.sql_comparator(); | ||
var condition = {}; | ||
|
||
|
@@ -408,12 +429,18 @@ function convertToDBVal(key, value, timezone) { | |
return condition; | ||
} | ||
|
||
return convertToDBType(key, value, timezone); | ||
|
||
} | ||
|
||
function convertToDBType(key, value, timezone) { | ||
|
||
if (Buffer.isBuffer(value)) { | ||
return new mongodb.Binary(value); | ||
} | ||
|
||
if (key == "_id" && typeof value == "string") { | ||
value = new mongodb.ObjectID(value); | ||
value = convertToID(value); | ||
} | ||
|
||
return value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can you remove this? Not needed in production code