hydrate-mongodb
Advanced tools
Comparing version 1.2.0 to 1.3.0
/** | ||
* @hidden | ||
*/ | ||
export declare function getDuration(start: [number, number]): number; | ||
export declare function getDuration(start: number[]): number; |
@@ -25,4 +25,3 @@ "use strict"; | ||
} | ||
var binary = value; | ||
return binary.read(0, binary.length()); | ||
return value.value(true); | ||
}; | ||
@@ -29,0 +28,0 @@ BufferMapping.prototype.write = function (context, value) { |
{ | ||
"name": "hydrate-mongodb", | ||
"description": "An Object Document Mapper (ODM) for MongoDB.", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": { | ||
"name": "Artifact Health, Inc", | ||
"name": "Artifact Health, LLC", | ||
"url": "http://www.artifacthealth.com" | ||
@@ -23,8 +23,6 @@ }, | ||
"dependencies": { | ||
"@types/mongodb": "^2.1.36", | ||
"@types/node": "^6.0.54", | ||
"@types/rx": "^2.5.34", | ||
"async": "^2.0.1", | ||
"change-case": "^2.2.0", | ||
"mongodb": "^2.2.16", | ||
"mongodb": "^2.1.19", | ||
"reflect-helper": "^1.0.2", | ||
@@ -31,0 +29,0 @@ "rx": "^4.1.0" |
@@ -94,7 +94,4 @@ import * as mongodb from "mongodb"; | ||
private _findOneAndModify(query, callback); | ||
private _removeOne(query, callback); | ||
private _removeAll(query, callback); | ||
private _updateOne(query, callback); | ||
private _updateAll(query, callback); | ||
private _upsert(query, callback); | ||
private _remove(query, callback); | ||
private _update(query, callback); | ||
private _distinct(query, callback); | ||
@@ -101,0 +98,0 @@ private _count(query, callback); |
@@ -127,3 +127,3 @@ "use strict"; | ||
} | ||
this._collection.findOne(criteria, { fields: fields }, function (err, document) { | ||
this._collection.findOne(criteria, fields, function (err, document) { | ||
if (err) | ||
@@ -207,3 +207,3 @@ return callback(err); | ||
var _this = this; | ||
this._collection.findOne(query.criteria, { fields: query.fields }, function (err, document) { | ||
this._collection.findOne(query.criteria, query.fields, function (err, document) { | ||
if (err) | ||
@@ -233,3 +233,3 @@ return callback(err); | ||
return error(err); | ||
cursor.next(function (err, item) { | ||
cursor.nextObject(function (err, item) { | ||
if (err) | ||
@@ -334,15 +334,9 @@ return error(err); | ||
case queryKind_1.QueryKind.RemoveOne: | ||
this._removeOne(query, handleCallback); | ||
break; | ||
case queryKind_1.QueryKind.RemoveAll: | ||
this._removeAll(query, handleCallback); | ||
this._remove(query, handleCallback); | ||
break; | ||
case queryKind_1.QueryKind.UpdateOne: | ||
this._updateOne(query, handleCallback); | ||
break; | ||
case queryKind_1.QueryKind.UpdateAll: | ||
this._updateAll(query, handleCallback); | ||
break; | ||
case queryKind_1.QueryKind.Upsert: | ||
this._upsert(query, handleCallback); | ||
this._update(query, handleCallback); | ||
break; | ||
@@ -395,3 +389,3 @@ case queryKind_1.QueryKind.Distinct: | ||
// try to retrieve a document from the cursor | ||
cursor.next(function (err, item) { | ||
cursor.nextObject(function (err, item) { | ||
if (err) | ||
@@ -412,3 +406,3 @@ return error(err); | ||
while (cursor.bufferedCount() > 0) { | ||
cursor.next(process); | ||
cursor.nextObject(process); | ||
} | ||
@@ -459,3 +453,3 @@ }); | ||
return error(err); | ||
cursor.next(function (err, item) { | ||
cursor.nextObject(function (err, item) { | ||
if (err) | ||
@@ -500,3 +494,3 @@ return error(err); | ||
PersisterImpl.prototype._prepareFind = function (query) { | ||
var cursor = this._collection.find(query.criteria).project(query.fields); | ||
var cursor = this._collection.find(query.criteria, query.fields); | ||
if (query.orderDocument !== undefined) { | ||
@@ -517,16 +511,9 @@ cursor.sort(query.orderDocument); | ||
PersisterImpl.prototype._findOneAndModify = function (query, callback) { | ||
var self = this; | ||
switch (query.kind) { | ||
case queryKind_1.QueryKind.FindOneAndRemove: | ||
this._collection.findOneAndDelete(query.criteria, findAndModifyCallback); | ||
break; | ||
default: | ||
this._collection.findOneAndUpdate(query.criteria, query.updateDocument, { | ||
returnOriginal: !query.wantsUpdated, | ||
upsert: query.kind == queryKind_1.QueryKind.FindOneAndUpsert, | ||
sort: query.orderDocument | ||
}, findAndModifyCallback); | ||
break; | ||
} | ||
function findAndModifyCallback(err, response) { | ||
var _this = this; | ||
var options = { | ||
remove: query.kind == queryKind_1.QueryKind.FindOneAndRemove, | ||
new: query.wantsUpdated, | ||
upsert: query.kind == queryKind_1.QueryKind.FindOneAndUpsert | ||
}; | ||
this._collection.findAndModify(query.criteria, query.orderDocument, query.updateDocument, options, function (err, response) { | ||
if (err) | ||
@@ -538,3 +525,3 @@ return callback(err); | ||
// check if the entity is already in the session | ||
var entity = self._session.getObject(document["_id"]); | ||
var entity = _this._session.getObject(document["_id"]); | ||
if (entity !== undefined) { | ||
@@ -549,3 +536,3 @@ // We check to see if the entity is already in the session so we know if we need to refresh the | ||
// The state may be changed to Removed below. | ||
self._loadOne(document, function (err, value) { | ||
_this._loadOne(document, function (err, value) { | ||
if (err) | ||
@@ -557,2 +544,3 @@ return callback(err); | ||
} | ||
var self = _this; | ||
function handleCallback() { | ||
@@ -564,3 +552,3 @@ // If the entity is not pending deletion, then see if we need to refresh the entity from the updated | ||
if (entity) { | ||
if (query.kind == queryKind_1.QueryKind.FindOneAndRemove) { | ||
if (options.remove) { | ||
// If entity was removed then notify the session that the entity has been removed from the | ||
@@ -570,3 +558,3 @@ // database. Note that the remove operation is not cascaded. | ||
} | ||
else if (!query.wantsUpdated && alreadyLoaded) { | ||
else if (options.new && alreadyLoaded) { | ||
// If findAndModify returned the updated document and the entity was already part of the session | ||
@@ -591,13 +579,9 @@ // before findAndModify was executed, then refresh the entity from the returned document. Note | ||
} | ||
} | ||
}; | ||
PersisterImpl.prototype._removeOne = function (query, callback) { | ||
this._collection.deleteOne(query.criteria, function (err, response) { | ||
if (err) | ||
return callback(err); | ||
callback(null, response.result.n); | ||
}); | ||
}; | ||
PersisterImpl.prototype._removeAll = function (query, callback) { | ||
this._collection.deleteMany(query.criteria, function (err, response) { | ||
PersisterImpl.prototype._remove = function (query, callback) { | ||
var options = { | ||
single: query.kind == queryKind_1.QueryKind.RemoveOne | ||
}; | ||
this._collection.remove(query.criteria, options, function (err, response) { | ||
if (err) | ||
@@ -608,4 +592,8 @@ return callback(err); | ||
}; | ||
PersisterImpl.prototype._updateOne = function (query, callback) { | ||
this._collection.updateOne(query.criteria, query.updateDocument, function (err, response) { | ||
PersisterImpl.prototype._update = function (query, callback) { | ||
var options = { | ||
multi: query.kind == queryKind_1.QueryKind.UpdateAll, | ||
upsert: query.kind == queryKind_1.QueryKind.Upsert | ||
}; | ||
this._collection.update(query.criteria, query.updateDocument, options, function (err, response) { | ||
if (err) | ||
@@ -616,16 +604,2 @@ return callback(err); | ||
}; | ||
PersisterImpl.prototype._updateAll = function (query, callback) { | ||
this._collection.updateMany(query.criteria, query.updateDocument, function (err, response) { | ||
if (err) | ||
return callback(err); | ||
callback(null, response.result.nModified); | ||
}); | ||
}; | ||
PersisterImpl.prototype._upsert = function (query, callback) { | ||
this._collection.updateOne(query.criteria, query.updateDocument, { upsert: true }, function (err, response) { | ||
if (err) | ||
return callback(err); | ||
callback(null, response.result.nModified); | ||
}); | ||
}; | ||
PersisterImpl.prototype._distinct = function (query, callback) { | ||
@@ -898,3 +872,3 @@ // TODO: add options for readpreference | ||
var _this = this; | ||
this._cursor.next(function (err, item) { | ||
this._cursor.nextObject(function (err, item) { | ||
if (err) | ||
@@ -901,0 +875,0 @@ return handleError(err); |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
@@ -3,0 +2,0 @@ import { Callback } from "./core/callback"; |
@@ -81,3 +81,3 @@ "use strict"; | ||
} | ||
collection.createIndex(keys, indexOptions, function (err, indexName) { | ||
collection.ensureIndex(keys, indexOptions, function (err, indexName) { | ||
if (err) | ||
@@ -108,3 +108,3 @@ return indexDone(err); | ||
if (collection) { | ||
collection.dropIndexes(function (err) { | ||
collection.dropAllIndexes(function (err) { | ||
if (err) | ||
@@ -111,0 +111,0 @@ return done(err); |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
@@ -3,0 +2,0 @@ import { ResultCallback } from "./core/callback"; |
6
400639
9607
- Removed@types/mongodb@^2.1.36
- Removed@types/node@^6.0.54
- Removed@types/bson@4.2.0(transitive)
- Removed@types/mongodb@2.2.28(transitive)
- Removed@types/node@6.14.13(transitive)
- Removedbson@6.7.0(transitive)
Updatedmongodb@^2.1.19