hydrate-mongodb
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "hydrate-mongodb", | ||
"description": "An Object Document Mapper (ODM) for MongoDB.", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Artifact Health, LLC", |
@@ -65,2 +65,10 @@ import { EventEmitter } from "events"; | ||
/** | ||
* Check by identifier if an entity exists. | ||
* @param ctr The constructor for the entity to find. | ||
* @param id The identifier for the entity. | ||
* @param callback Called with a boolean indicating if an entity with exists or not. Note that if an entity is pending removal then the | ||
* value will be false. | ||
*/ | ||
exists<T>(ctr: Constructor<T>, id: any, callback: ResultCallback<boolean>): void; | ||
/** | ||
* Gets a reference to an entity without making a request to the database. | ||
@@ -175,2 +183,3 @@ * @param ctr The constructor for the entity. | ||
find<T>(ctr: Constructor<T>, id: any, callback?: ResultCallback<T>): FindOneQuery<T>; | ||
exists<T>(ctr: Constructor<T>, id: any, callback: ResultCallback<boolean>): void; | ||
fetch<T>(obj: T, pathsOrCallback: any, callback?: ResultCallback<T>): void; | ||
@@ -177,0 +186,0 @@ close(callback?: Callback): void; |
@@ -81,2 +81,22 @@ "use strict"; | ||
}; | ||
SessionImpl.prototype.exists = function (ctr, id, callback) { | ||
// check the identity map for the identifier | ||
var obj = this.getObject(id); | ||
// if we get an object back then entity is managed | ||
if (obj) { | ||
process.nextTick(function () { return callback(null, true); }); | ||
return; | ||
} | ||
// if null then entity is pending removal | ||
if (obj === null) { | ||
process.nextTick(function () { return callback(null, false); }); | ||
return; | ||
} | ||
// otherwise, check the database | ||
this.query(ctr).count({ _id: id }, function (err, count) { | ||
if (err) | ||
return callback(err); | ||
callback(null, count >= 0); | ||
}); | ||
}; | ||
SessionImpl.prototype.fetch = function (obj, pathsOrCallback, callback) { | ||
@@ -83,0 +103,0 @@ var paths; |
398782
9575