Skip to content

Commit

Permalink
Add open method to Db class
Browse files Browse the repository at this point in the history
  • Loading branch information
erikolson186 committed Feb 19, 2017
1 parent c9f5abc commit bc62520
Show file tree
Hide file tree
Showing 15 changed files with 5,140 additions and 4,624 deletions.
2 changes: 1 addition & 1 deletion build/src/collection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

Expand Down
40 changes: 15 additions & 25 deletions build/src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ var Cursor = function (_EventEmitter) {

fn(doc);

_this7.forEach(fn, cb);
_this7._forEach(fn, cb);
});
}

Expand Down Expand Up @@ -437,6 +437,14 @@ var Cursor = function (_EventEmitter) {

return this;
}
}, {
key: '_addStage',
value: function _addStage(fn, arg) {
this._assertUnopened();
this._pipeline.push([fn, arg]);

return this;
}

/**
* Limit the number of documents that can be iterated.
Expand All @@ -450,10 +458,7 @@ var Cursor = function (_EventEmitter) {
}, {
key: 'limit',
value: function limit(num) {
this._assertUnopened();
this._pipeline.push([_limit, num]);

return this;
return this._addStage(_limit, num);
}

/**
Expand All @@ -468,10 +473,7 @@ var Cursor = function (_EventEmitter) {
}, {
key: 'skip',
value: function skip(num) {
this._assertUnopened();
this._pipeline.push([_skip, num]);

return this;
return this._addStage(_skip, num);
}

/**
Expand All @@ -486,10 +488,7 @@ var Cursor = function (_EventEmitter) {
}, {
key: 'project',
value: function project(spec) {
this._assertUnopened();
this._pipeline.push([_project, spec]);

return this;
return this._addStage(_project, spec);
}

/**
Expand All @@ -508,10 +507,7 @@ var Cursor = function (_EventEmitter) {
}, {
key: 'group',
value: function group(spec) {
this._assertUnopened();
this._pipeline.push([_group, spec]);

return this;
return this._addStage(_group, spec);
}

/**
Expand All @@ -526,10 +522,7 @@ var Cursor = function (_EventEmitter) {
}, {
key: 'unwind',
value: function unwind(path) {
this._assertUnopened();
this._pipeline.push([_unwind, path]);

return this;
return this._addStage(_unwind, path);
}

/**
Expand Down Expand Up @@ -558,10 +551,7 @@ var Cursor = function (_EventEmitter) {
}, {
key: 'sort',
value: function sort(spec) {
this._assertUnopened();
this._pipeline.push([_sort, spec]);

return this;
return this._addStage(_sort, spec);
}
}, {
key: '_initSort',
Expand Down
28 changes: 27 additions & 1 deletion build/src/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

Expand Down Expand Up @@ -276,6 +276,32 @@ var Db = function (_EventEmitter) {
return col;
}

/**
* Open connection to the database.
* @param {function} [cb] The result callback.
* @return {Promise}
*/

}, {
key: 'open',
value: function open(cb) {
var _this3 = this;

var deferred = Q.defer();

this._getConn(function (error) {
if (error) {
deferred.reject(error);
} else {
deferred.resolve(_this3);
}
});

deferred.promise.nodeify(cb);

return deferred.promise;
}

/**
* Close the connection if it is open.
*/
Expand Down
2 changes: 1 addition & 1 deletion build/src/group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };

Expand Down
2 changes: 1 addition & 1 deletion build/src/project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

Expand Down
2 changes: 1 addition & 1 deletion build/src/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var deepMerge = require('deepmerge'),
clone = require('clone'),
Expand Down
Loading

0 comments on commit bc62520

Please sign in to comment.