Skip to content

Commit

Permalink
Updated to support MongoDB Node driver v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 27, 2015
1 parent 190e5c2 commit cce0311
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 60 deletions.
27 changes: 14 additions & 13 deletions lib/Cursor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cursor.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions lib/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Cursor<TDocument extends { _id?: any }, TInstance> {
* @constructor
*/
constructor(private model: Model<TDocument, TInstance>, private conditions: any, public cursor: MongoDB.Cursor) {

}

/**
Expand All @@ -39,13 +39,14 @@ class Cursor<TDocument extends { _id?: any }, TInstance> {
* @param {function(Error)} callback A callback which is triggered when all operations have been dispatched
* @return {Promise} A promise which is resolved when all operations have been dispatched
*/
each(handler: (instance: TInstance) => void, callback?: General.Callback<void>): Bluebird<void> {
forEach(handler: (instance: TInstance) => void, callback?: General.Callback<void>): Bluebird<void> {
var helpers = this.model.helpers;
return new Bluebird<void>((resolve, reject) => {
this.cursor.each((err, item: TDocument) => {
if (err) return reject(err);
if (!item) return resolve(null);
this.cursor.forEach((item: TDocument) => {
this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); }).then(handler);
},(err) => {
if (err) return reject(err);
return resolve(null);
});
}).nodeify(callback);
}
Expand All @@ -60,11 +61,12 @@ class Cursor<TDocument extends { _id?: any }, TInstance> {
var helpers = this.model.helpers;
return new Bluebird<TResult[]>((resolve, reject) => {
var promises: Bluebird<TResult>[] = [];
this.cursor.each((err, item: TDocument) => {
if (err) return reject(err);
if (!item) return resolve(Bluebird.all(promises));
this.cursor.forEach((item: TDocument) => {
promises.push(this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); })
.then(<(instance) => TResult>transform));
},(err) => {
if (err) return reject(err);
return resolve(Bluebird.all(promises));
});
}).nodeify(callback);
}
Expand Down Expand Up @@ -93,7 +95,7 @@ class Cursor<TDocument extends { _id?: any }, TInstance> {
*/
next(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
return new Bluebird<TDocument>((resolve, reject) => {
this.cursor.nextObject((err, result: any) => {
this.cursor.next((err, result: any) => {
if (err) return reject(err);
return resolve(<any>result);
});
Expand All @@ -107,7 +109,8 @@ class Cursor<TDocument extends { _id?: any }, TInstance> {
* @return {Cursor} The new cursor which starts at the beginning of the results
*/
rewind(): Cursor<TDocument, TInstance> {
return new Cursor(this.model, this.conditions, this.cursor.rewind());
this.cursor.rewind();
return this;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/Model.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Model.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ class Model<TDocument extends { _id?: any }, TInstance> implements ModelInterfac
else
return this._handlers.creatingDocuments(objects).then((objects) => {
return new Bluebird<any[]>((resolve, reject) => {
this.collection.insert(objects, queryOptions,(err, results) => {
this.collection.insert(objects, queryOptions,(err, result) => {
if (err) return reject(err);
return resolve(results);
return resolve(result.ops);
});
});
});
Expand Down Expand Up @@ -504,9 +504,9 @@ class Model<TDocument extends { _id?: any }, TInstance> implements ModelInterfac
conditions['_id'] = this.options.identifier.reverse(conditions['_id']);

return new Bluebird<number>((resolve, reject) => {
this.collection.update(conditions, changes, options,(err, changes) => {
this.collection.update(conditions, changes, options,(err, result) => {
if (err) return reject(err);
return resolve(changes);
return resolve(result.result.nModified);
});
})
}).nodeify(callback);
Expand Down Expand Up @@ -580,9 +580,9 @@ class Model<TDocument extends { _id?: any }, TInstance> implements ModelInterfac
conditions['_id'] = this.options.identifier.reverse(conditions['_id']);

return new Bluebird<number>((resolve, reject) => {
this.collection.remove(conditions,(err, results) => {
this.collection.remove(conditions,(err, response) => {
if (err) return reject(err);
return resolve(results);
return resolve(response.result.n);
});
});
}).then((count) => {
Expand Down
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iridium",
"version": "4.0.1",
"version": "5.0.0-alpha",
"author": "Benjamin Pannell <admin@sierrasoftworks.com>",
"description": "A custom lightweight ORM for MongoDB designed for power-users",
"homepage": "https://sierrasoftworks.com/iridium",
Expand All @@ -27,14 +27,10 @@
"node": ">= 0.8"
},
"dependencies": {
"async": "~0.9",
"bluebird": "2.x",
"concoction": "~1.0",
"debug": "^1.0.4",
"functionality": "2.x",
"lodash": "*",
"mongodb": "^1.4.35",
"skmatc": "1.x"
"bluebird": "^2.9.24",
"lodash": "^3.7.0",
"mongodb": "^2.0.28",
"skmatc": "^1.1.2"
},
"devDependencies": {
"mocha": "2.x",
Expand All @@ -54,7 +50,6 @@
"odm",
"iridium",
"validation",
"transformation",
"preprocessing"
]
}

0 comments on commit cce0311

Please sign in to comment.