Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/unfold/mongode

  • Loading branch information...
commit 7f9f3df0fa054ca4eef79095a3a3859d94d4c0ab 2 parents 6efd0f5 + f8265ea
Vinay Pulim authored
Showing with 41 additions and 38 deletions.
  1. +2 −1  index.js
  2. +9 −9 lib/collection.js
  3. +5 −5 lib/cursor.js
  4. +25 −23 lib/db.js
View
3  index.js
@@ -4,9 +4,10 @@ function connect(name, serverURIs, options) {
if (!exports[name]) {
exports[name] = new db.Database(name, serverURIs, options);
}
-
+
return exports[name];
}
exports.connect = connect;
exports.Database = db.Database;
+exports.ObjectID = db.ObjectID;
View
18 lib/collection.js
@@ -11,7 +11,7 @@ var Collection = function(name, options, connectCallback) {
this._isConnected = false;
this._callback = connectCallback || function () {};
this._waiting = [];
-}
+};
Collection.prototype.getName = function() {
return this._name;
@@ -22,8 +22,8 @@ Collection.prototype.getOptions = function() {
};
Collection.prototype.getCallback = function() {
- return this._callback;
-}
+ return this._callback;
+};
Collection.prototype._connected = function(collection) {
var self = this;
@@ -34,9 +34,9 @@ Collection.prototype._connected = function(collection) {
var fn = collection[cursor.command],
c = fn.apply(collection, cursor.args);
cursor._connected(c);
- };
+ }
self._waiting = [];
-}
+};
Collection.functions = [
'insert',
@@ -77,8 +77,8 @@ Collection.functions.forEach(function(name) {
if (self._isConnected) {
if (isCursorOp) {
process.nextTick(function() {
- self._connected(self._collection);
- })
+ self._connected(self._collection);
+ });
}
else {
self._connected(self._collection);
@@ -86,7 +86,7 @@ Collection.functions.forEach(function(name) {
}
return isCursorOp ? cursor : null;
- }
-})
+ };
+});
exports.Collection = Collection;
View
10 lib/cursor.js
@@ -4,7 +4,7 @@ var Cursor = function(command, args) {
this._cursor = null;
this._waiting = [];
this._hasCallback = false;
-}
+};
Cursor.prototype._connected = function(cursor) {
var self = this;
@@ -14,10 +14,10 @@ Cursor.prototype._connected = function(cursor) {
self._waiting.forEach(function(op) {
var fn = self._cursor[op.command];
- fn.apply(self._cursor, op.args)
+ fn.apply(self._cursor, op.args);
});
self._waiting = [];
-}
+};
Cursor.functions = [
'rewind',
@@ -47,11 +47,11 @@ Cursor.functions.forEach(function(name) {
if (self._isConnected) {
process.nextTick(function() {
self._connected(self._cursor);
- })
+ });
}
return self;
- }
+ };
});
exports.Cursor = Cursor;
View
48 lib/db.js
@@ -6,7 +6,7 @@ var mongodb = require('mongodb'),
var Database = function(name, servers, options) {
EventEmitter.call(this);
-
+
var self = this,
serverConfig;
@@ -14,18 +14,18 @@ var Database = function(name, servers, options) {
self._waiting = [];
self._isConnected = false;
-
+
if (Array.isArray(servers)) {
- servers = servers.map(function(server) {
- return Database._newServer(server, options);
+ servers = servers.map(function(server) {
+ return createServer(server, options);
});
serverConfig = new mongodb.ReplSetServers(servers, options);
}
else {
- serverConfig = Database._newServer(servers, options);
+ serverConfig = createServer(servers, options);
}
- self._db = new mongodb.Db(name, serverConfig)
+ self._db = new mongodb.Db(name, serverConfig);
self._db.open(function(err) {
if (err) {
@@ -34,12 +34,13 @@ var Database = function(name, servers, options) {
else {
self._connected();
}
- })
+ });
// expose useful Db members
self.bson_serializer = self._db.bson_serializer;
self.bson_deserializer = self._db.bson_deserializer;
-}
+};
+
util.inherits(Database, EventEmitter);
Database.prototype.collection = function(name, options, callback) {
@@ -48,39 +49,39 @@ Database.prototype.collection = function(name, options, callback) {
}
var self = this,
- collection = new Collection(name, options, callback);
-
+ collection = new Collection(name, options, callback);
+
self._waiting.push(collection);
if (self._isConnected) {
process.nextTick(function() {
- self._connected();
- })
+ self._connected();
+ });
}
-
+
this[name] = collection;
var obj = this;
var parts = name.split('.');
if (parts.length > 1) {
parts.forEach(function(part, i) {
if (i == parts.length - 1) {
- obj[part] = collection;
+ obj[part] = collection;
}
else {
obj = obj[part] = {};
}
- })
+ });
}
return collection;
-}
+};
Database.prototype._connected = function() {
var self = this,
db = self._db;
self._isConnected = true;
-
+
self._waiting.forEach(function(collection) {
db.collection(collection.getName(), collection.getOptions(), function(err, c) {
var connectCallback = collection.getCallback();
@@ -89,20 +90,21 @@ Database.prototype._connected = function() {
connectCallback(err);
}
else {
- collection._connected(c);
+ collection._connected(c);
connectCallback(null, collection);
}
});
});
self._waiting = [];
-}
+};
-Database._newServer = function(server, options) {
+var createServer = function(server, options) {
var parts = server.split(':'),
host = parts[0],
port = parseInt(parts[1] || 27017, 10);
- return new mongodb.Server(host, port, options)
-}
+ return new mongodb.Server(host, port, options);
+};
-exports.Database = Database;
+exports.Database = Database;
+exports.ObjectID = mongodb.BSONPure.ObjectID;
Please sign in to comment.
Something went wrong with that request. Please try again.