all files / todo/ db.js

100% Statements 13/13
100% Branches 2/2
100% Functions 4/4
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46            37×                                                      
//START:REQUIRE
var MongoClient = require('mongodb').MongoClient;
//END:REQUIRE
 
//START:GET
module.exports = {
  connection: null,
  
  get: function() { return this.connection; },
//END:GET
 
//START:CLOSE1
//START:CLOSE
   close: function() {
//END:CLOSE1
     if(this.connection) {
       this.connection.close();
//START:CLOSE1
       this.connection = null;
//END:CLOSE1
     }
//START:CLOSE1
   },
//END:CLOSE
//END:CLOSE1
 
//START:CONNECT
  connect: function(dbname, callback) {
    var self = this;
  
    var cacheConnection = function(err, db) {
      self.connection= db;
      callback(err);
    }
  
    try {
      MongoClient.connect(dbname, cacheConnection);
    } catch(ex) {
      callback(ex);
    }
  }
//END:CONNECT
  
//START:GET
}
//END:GET