Created
August 22, 2010 15:31
-
-
Save tobiassjosten/543892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongodb = require('mongodb'); | |
var Db = mongodb.Db; | |
var Server = mongodb.Server; | |
module.exports = Database; | |
function Database(database_name, host, port) { | |
this.client = new Db(database_name, new Server(host, port, {})); | |
this.find = function(collection_name, params, callback) { | |
this.client.collection(collection_name, function(err, collection) { | |
collection.find(params, function(err, cursor) { | |
cursor.toArray(function(err, results) { | |
callback(results); | |
}); | |
}); | |
}); | |
} | |
} | |
Database.prototype = new process.EventEmitter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports['connect'] = function(test){ | |
test.expect(0); | |
var Database = require('database'); | |
var database = new Database('ubertest', '127.0.0.1', 27017); | |
database.find('characters', {name:'Tobias'}, function(characters) { | |
console.log(require('sys').inspect('callback', true, null)); | |
console.log(require('sys').inspect(characters, true, null)); | |
}); | |
test.done(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment