Comparing version 3.0.8 to 3.0.9
@@ -24,3 +24,3 @@ 'use strict'; | ||
if (!schema) { | ||
return; | ||
return null; | ||
} | ||
@@ -67,3 +67,4 @@ | ||
/** | ||
* @class ODM Object Document Model | ||
* Object Document Model | ||
* @name ODM | ||
*/ | ||
@@ -93,5 +94,4 @@ var ODM = { | ||
connect: function (url, options, callback) { | ||
var self = this; | ||
// disconnect any open connection | ||
self.disconnect(); | ||
ODM.disconnect(); | ||
@@ -113,5 +113,5 @@ _url = url; | ||
self.db = db; | ||
ODM.db = db; | ||
self.db.on('close', function (err) { | ||
ODM.db.on('close', function (err) { | ||
// clear collection cache | ||
@@ -127,3 +127,3 @@ _collections = {}; | ||
callback(null); | ||
return callback(null); | ||
}); | ||
@@ -134,2 +134,3 @@ | ||
} | ||
return null; | ||
}, | ||
@@ -145,7 +146,7 @@ | ||
disconnect: function (callback) { | ||
if (this.db) { | ||
if (ODM.db) { | ||
if (callback !== undefined) { | ||
this.db.close(callback); | ||
ODM.db.close(callback); | ||
} else { | ||
this.db.close(); | ||
ODM.db.close(); | ||
} | ||
@@ -174,9 +175,6 @@ // clear collection cache | ||
var self = this; | ||
if (_connecting) { | ||
var odm = this; | ||
// delay this request since we are in transit to get a new connection | ||
setTimeout(function () { | ||
odm.collection(collection_name, options, callback); | ||
return setTimeout(function () { | ||
ODM.collection(collection_name, options, callback); | ||
}, 300); | ||
@@ -196,7 +194,7 @@ } else if (!_connected) { | ||
self.db = db; | ||
ODM.db = db; | ||
_connected = true; | ||
_collections = {}; | ||
self.db.collection(collection_name, options, function (err, collection) { | ||
return ODM.db.collection(collection_name, options, function (err, collection) { | ||
if (!err) { | ||
@@ -211,11 +209,12 @@ _collections[collection_name] = collection; | ||
_connecting = true; | ||
return null; | ||
} else { | ||
if (_collections[collection_name]) { | ||
callback(null, _collections[collection_name]); | ||
return callback(null, _collections[collection_name]); | ||
} else { | ||
self.db.collection(collection_name, options, function (err, collection) { | ||
return ODM.db.collection(collection_name, options, function (err, collection) { | ||
if (!err) { | ||
_collections[collection_name] = collection; | ||
} | ||
callback(err, collection); | ||
return callback(err, collection); | ||
}); | ||
@@ -227,3 +226,3 @@ } | ||
findOne: function (collection_name, query, fields, options, callback) { | ||
this.collection(collection_name, options, function (err, collection) { | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
@@ -233,3 +232,3 @@ return callback(err); | ||
collection.findOne(query, fields, options, callback); | ||
return collection.findOne(query, fields, options, callback); | ||
}); | ||
@@ -241,3 +240,3 @@ }, | ||
this.collection(collection_name, options, function (err, collection) { | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
@@ -247,3 +246,3 @@ return callback(err); | ||
collection.find(query, fields, options, function (err, cursor) { | ||
return collection.find(query, fields, options, function (err, cursor) { | ||
if (err) { | ||
@@ -261,3 +260,3 @@ return callback(err); | ||
cursor.toArray(callback); | ||
return cursor.toArray(callback); | ||
}); | ||
@@ -268,3 +267,3 @@ }); | ||
insert: function (collection_name, documents, options, callback) { | ||
this.collection(collection_name, options, function (err, collection) { | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
@@ -275,3 +274,3 @@ return callback(err); | ||
options.safe = _safeOptions; | ||
collection.insert(documents, options, callback); | ||
return collection.insert(documents, options, callback); | ||
}); | ||
@@ -281,3 +280,3 @@ }, | ||
update: function (collection_name, criteria, document, options, callback) { | ||
this.collection(collection_name, options, function (err, collection) { | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
@@ -288,3 +287,3 @@ return callback(err); | ||
options.safe = _safeOptions; | ||
collection.update(criteria, document, options, callback); | ||
return collection.update(criteria, document, options, callback); | ||
}); | ||
@@ -294,3 +293,3 @@ }, | ||
save: function (collection_name, document, options, callback) { | ||
this.collection(collection_name, options, function (err, collection) { | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
@@ -301,3 +300,3 @@ return callback(err); | ||
options.safe = _safeOptions; | ||
collection.save(document, options, callback); | ||
return collection.save(document, options, callback); | ||
}); | ||
@@ -307,3 +306,3 @@ }, | ||
remove: function (collection_name, query, options, callback) { | ||
this.collection(collection_name, options, function (err, collection) { | ||
ODM.collection(collection_name, options, function (err, collection) { | ||
if (err) { | ||
@@ -313,3 +312,3 @@ return callback(err); | ||
collection.remove(query, options, callback); | ||
return collection.remove(query, options, callback); | ||
}); | ||
@@ -330,10 +329,7 @@ }, | ||
* | ||
* @return {Model} | ||
* @return {Function} | ||
*/ | ||
embeddedModel: function (schemaDef) { | ||
var odm = this; | ||
if (schemaDef !== undefined && schemaDef !== null) { | ||
return embedSchemaModel(odm, schemaDef); | ||
return embedSchemaModel(ODM, schemaDef); | ||
} | ||
@@ -353,7 +349,4 @@ | ||
basicModel: function (mongoCollection) { | ||
var odm = this; | ||
if (mongoCollection !== undefined) { | ||
return baseModel(odm, mongoCollection); | ||
return baseModel(ODM, mongoCollection); | ||
} | ||
@@ -374,8 +367,5 @@ | ||
schemaModel: function (mongoCollection, schemaDef) { | ||
var odm = this; | ||
if (schemaDef !== undefined && schemaDef !== null) { | ||
if (mongoCollection !== undefined) { | ||
return schemaModel(odm, mongoCollection, schemaDef); | ||
return schemaModel(ODM, mongoCollection, schemaDef); | ||
} | ||
@@ -382,0 +372,0 @@ } |
@@ -24,4 +24,7 @@ 'use strict'; | ||
/** | ||
* Document EmbeddedModel Customized class for a mongodb document schema. | ||
* | ||
* @name EmbeddedModel | ||
* @class Document EmbeddedModel Customized class for a mongodb document schema. | ||
* @class EmbeddedModel | ||
* @constructor | ||
* @param {Object} [json] if provided will update the current instance with the json properties | ||
@@ -51,3 +54,2 @@ */ | ||
* schema for embedded objects | ||
* | ||
* @memberOf EmbeddedModel | ||
@@ -64,3 +66,3 @@ */ | ||
* Verifies if an Object is valid against the configured validator | ||
* | ||
* @memberOf EmbeddedModel | ||
* @param {Boolean} [verbose] | ||
@@ -91,3 +93,3 @@ * @return {Boolean|Object} | ||
* Helper to have a short syntax | ||
* | ||
* @memberOf EmbeddedModel | ||
* @return {Boolean} | ||
@@ -102,2 +104,4 @@ */ | ||
* @deprecated | ||
* @static | ||
* @memberOf EmbeddedModel | ||
* @param path {String} Path to be updated | ||
@@ -104,0 +108,0 @@ * @param type {Object} Type prototype to be copied |
@@ -36,4 +36,5 @@ 'use strict'; | ||
/** | ||
* Document Customized class for a mongodb document schema. | ||
* @name BaseModel | ||
* @class Document Customized class for a mongodb document schema. | ||
* @class BaseModel | ||
* @constructor | ||
@@ -47,2 +48,3 @@ */ | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -97,3 +99,3 @@ * @param {Object} query Query object as in mongodb documentation | ||
documentLoaded[PROTO] = BaseModel.prototype; | ||
callback(null, documentLoaded); | ||
return callback(null, documentLoaded); | ||
}); | ||
@@ -105,2 +107,3 @@ }; | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -153,3 +156,3 @@ * @param {ObjectID|String} id Either a ObjectId instance or, the function will try to cast it to ObjectId. | ||
odm.findOne(mongoCollection, {_id: _id}, fields, options, function (err, documentLoaded) { | ||
return odm.findOne(mongoCollection, {_id: _id}, fields, options, function (err, documentLoaded) { | ||
if (err) { | ||
@@ -173,3 +176,3 @@ return callback(err); | ||
documentLoaded[PROTO] = BaseModel.prototype; | ||
callback(null, documentLoaded); | ||
return callback(null, documentLoaded); | ||
}); | ||
@@ -181,2 +184,3 @@ }; | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -244,2 +248,3 @@ * @param {Object} query MongoDB Query | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -258,2 +263,3 @@ * @param {Object|Function} [fields] filter the fields to be returned | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -300,3 +306,3 @@ * @param {ObjectID|ObjectID[]} ids single or array of ObjectId objects | ||
if (ids.length === 0) { | ||
callback(null, []); | ||
return callback(null, []); | ||
} else { | ||
@@ -327,3 +333,3 @@ // convert the orig array to an index | ||
odm.find(mongoCollection, {_id: {'$in': idsToFind}}, fields, options, function (err, documentsLoaded) { | ||
return odm.find(mongoCollection, {_id: {'$in': idsToFind}}, fields, options, function (err, documentsLoaded) { | ||
if (err) { | ||
@@ -352,3 +358,3 @@ return callback(err); | ||
callback(null, result); | ||
return callback(null, result); | ||
}); | ||
@@ -361,2 +367,4 @@ } | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
* @param fieldOrSpec | ||
@@ -423,3 +431,3 @@ * @param [options] | ||
odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) { | ||
return odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) { | ||
if (err) { | ||
@@ -446,3 +454,3 @@ return callback(err); | ||
documentLoaded[PROTO] = BaseModel.prototype; | ||
callback(null, documentLoaded); | ||
return callback(null, documentLoaded); | ||
}); | ||
@@ -458,3 +466,3 @@ }; | ||
collection.ensureIndex(fieldOrSpec, options, callback); | ||
return collection.ensureIndex(fieldOrSpec, options, callback); | ||
}); | ||
@@ -488,3 +496,3 @@ }; | ||
} | ||
callback(null, self._id); | ||
return callback(null, self._id); | ||
}); | ||
@@ -554,3 +562,3 @@ }; | ||
odm.update(mongoCollection, {_id: self._id}, partUpdate !== undefined ? partUpdate : self, options, callback); | ||
return odm.update(mongoCollection, {_id: self._id}, partUpdate !== undefined ? partUpdate : self, options, callback); | ||
}; | ||
@@ -590,2 +598,7 @@ | ||
/** | ||
* @memberOf BaseModel | ||
* @param {Object} options | ||
* @param {Function} callback | ||
*/ | ||
BaseModel.prototype.reload = function (options, callback) { | ||
@@ -604,3 +617,3 @@ if (callback === undefined) { | ||
BaseModel.findById(_id, options, function (err, documentLoaded) { | ||
return BaseModel.findById(_id, options, function (err, documentLoaded) { | ||
if (err) { | ||
@@ -624,3 +637,3 @@ return callback(err); | ||
callback(null); | ||
return callback(null); | ||
}); | ||
@@ -632,2 +645,3 @@ }; | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -650,2 +664,3 @@ * @param {Object} query Search query of objects to remove | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -667,2 +682,3 @@ * @param {Object|Function} [options] options for the query | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -684,2 +700,3 @@ * @param {Object|Function} [options] options for the query | ||
* | ||
* @static | ||
* @memberOf BaseModel | ||
@@ -686,0 +703,0 @@ * @param {Object} query Search query of objects to remove |
@@ -36,3 +36,5 @@ 'use strict'; | ||
/** | ||
* @name SchemaModel | ||
* @class SchemaModel | ||
* @constructor | ||
* @param {Object} [json] if provided will update the current instance with the json properties | ||
@@ -62,3 +64,2 @@ */ | ||
* schema for embedded objects | ||
* | ||
* @memberOf SchemaModel | ||
@@ -75,3 +76,3 @@ */ | ||
* Verifies if an Object is valid against the configured validator | ||
* | ||
* @memberOf SchemaModel | ||
* @param {Boolean} [verbose] | ||
@@ -102,3 +103,3 @@ * @return {Boolean|Object} | ||
* Helper to have a short syntax | ||
* | ||
* @memberOf SchemaModel | ||
* @return {Boolean} | ||
@@ -113,2 +114,4 @@ */ | ||
* @deprecated | ||
* @static | ||
* @memberOf SchemaModel | ||
* @param path {String} Path to be updated | ||
@@ -126,2 +129,3 @@ * @param type {Object} Type prototype to be copied | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -175,3 +179,3 @@ * @param {Object} query Query object as in mongodb documentation | ||
callback(null, documentLoaded); | ||
return callback(null, documentLoaded); | ||
}); | ||
@@ -183,2 +187,3 @@ }; | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -231,3 +236,3 @@ * @param {ObjectID|String} id Either a ObjectId instance or, the function will try to cast it to ObjectId. | ||
odm.findOne(mongoCollection, {_id: _id}, fields, options, function (err, documentLoaded) { | ||
return odm.findOne(mongoCollection, {_id: _id}, fields, options, function (err, documentLoaded) { | ||
if (err) { | ||
@@ -249,3 +254,3 @@ return callback(err); | ||
} | ||
callback(null, documentLoaded); | ||
return callback(null, documentLoaded); | ||
}); | ||
@@ -257,2 +262,3 @@ }; | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -296,2 +302,3 @@ * @param {Object} query MongoDB Query | ||
if (wantCursor) { | ||
/* | ||
var origEach = documentsLoaded.each; | ||
@@ -337,3 +344,3 @@ var origNextObject = documentsLoaded.nextObject; | ||
}; | ||
*/ | ||
return callback(null, documentsLoaded); | ||
@@ -354,3 +361,3 @@ } | ||
} | ||
callback(null, documentsLoaded); | ||
return callback(null, documentsLoaded); | ||
}); | ||
@@ -362,2 +369,3 @@ }; | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -376,2 +384,3 @@ * @param {Object|Function} [fields] filter the fields to be returned | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -445,3 +454,3 @@ * @param {ObjectID|ObjectID[]} ids single or array of ObjectId objects | ||
odm.find(mongoCollection, {_id: {'$in': idsToFind}}, fields, options, function (err, documentsLoaded) { | ||
return odm.find(mongoCollection, {_id: {'$in': idsToFind}}, fields, options, function (err, documentsLoaded) { | ||
if (err) { | ||
@@ -471,3 +480,3 @@ return callback(err); | ||
callback(null, result); | ||
return callback(null, result); | ||
}); | ||
@@ -480,2 +489,4 @@ }; | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
* @param fieldOrSpec | ||
@@ -538,3 +549,3 @@ * @param [options] | ||
odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) { | ||
return odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) { | ||
if (err) { | ||
@@ -560,3 +571,3 @@ return callback(err); | ||
} | ||
callback(null, documentLoaded); | ||
return callback(null, documentLoaded); | ||
}); | ||
@@ -572,3 +583,3 @@ }; | ||
collection.ensureIndex(fieldOrSpec, options, callback); | ||
return collection.ensureIndex(fieldOrSpec, options, callback); | ||
}); | ||
@@ -597,3 +608,3 @@ }; | ||
odm.save(mongoCollection, self, options, function (err, savedDocument) { | ||
return odm.save(mongoCollection, self, options, function (err, savedDocument) { | ||
if (err) { | ||
@@ -608,3 +619,3 @@ return callback(err); | ||
} | ||
callback(null, self._id); | ||
return callback(null, self._id); | ||
}); | ||
@@ -685,3 +696,3 @@ }; | ||
odm.update(mongoCollection, {_id: self._id}, partUpdate !== undefined ? partUpdate : self, options, callback); | ||
return odm.update(mongoCollection, {_id: self._id}, partUpdate !== undefined ? partUpdate : self, options, callback); | ||
}; | ||
@@ -704,6 +715,6 @@ | ||
if (validation !== null) { | ||
return callback(validation); | ||
callback(validation); | ||
} else { | ||
odm.insert(mongoCollection, this, options, callback); | ||
} | ||
odm.insert(mongoCollection, this, options, callback); | ||
}; | ||
@@ -725,2 +736,3 @@ | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -736,2 +748,3 @@ * @param {Object} query Search query of objects to remove | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -746,2 +759,3 @@ * @param {Object|Function} [options] options for the query | ||
* | ||
* @static | ||
* @memberOf SchemaModel | ||
@@ -748,0 +762,0 @@ * @param {Object} query Search query of objects to remove |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "3.0.8", | ||
"version": "3.0.9", | ||
"engines": { | ||
@@ -11,0 +11,0 @@ "node": ">=0.4.12" |
68369
2174