Code coverage report for node-mongoskin/lib/db.js

Statements: 100% (29 / 29)      Branches: 75% (3 / 4)      Functions: 100% (5 / 5)      Lines: 100% (29 / 29)      Ignored: none     

All files » node-mongoskin/lib/ » db.js
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80                              1 1 1 1 1 1 1         1   1   2 1 1 1 1                       1             22 22 22 22               1 2     1 2     1 2 2 2 2 2    
/*!
 * mongoskin - db.js
 *
 * Copyright(c) 2011 - 2012 kissjs.org
 * Copyright(c) 2012 fengmk2 <fengmk2@gmail.com>
 * MIT Licensed
 */
 
"use strict";
 
/**
 * Module dependencies.
 * TODO db.gridfs()
 */
 
var mongodb = require('mongodb');
var Db = mongodb.Db;
var MongoClient = mongodb.MongoClient;
var utils = require('./utils');
var SkinAdmin = require('./admin').SkinAdmin;
var SkinCollection = require('./collection').SkinCollection;
var SkinGridStore = require('./grid_store').SkinGridStore;
 
/**
 * Constructor
 */
var SkinDb = exports.SkinDb = utils.makeSkinClass(Db, true);
 
SkinDb.prototype._open = function(callback) {
  // TODO authenticate support
  if(this._native) {
    this._native.open(callback);
  } else Eif(this._connect_args) {
    var args = this._connect_args.concat(callback);
    MongoClient.connect.apply(MongoClient, args);
  }
}
 
/**
 * Create or retrieval skin collection
 *
 * @param {String} name, the collection name.
 * @param {Object} [options] collection options.
 * @return {SkinCollection}
 * @api public
 */
SkinDb.prototype.collection = function (name, options) {
  // Ooops, no extended mthods like findById etc.
  // if(this.isOpen() && (!options || !options.strict) && !callback) {
  //   // mongodb now support collection without callback
  //   // see: http://mongodb.github.io/node-mongodb-native/api-generated/db.html#collection
  //   return this._native.collection(name, options);
  // }
  var collection = new SkinCollection();
  collection._skin_db = this;
  collection._collection_args = [name, options];
  return collection;
};
 
/**
 * @param {String} name the collection name
 * @param {Object} [options] collection options
 * @return {SkinCollection} collection
 */
SkinDb.prototype.bind = function (name, options) {
  return this[name] = this.collection(name, options);
}
 
SkinDb.prototype.admin = function () {
  return new SkinAdmin(this);
}
 
SkinDb.prototype.gridStore = function () {
  var skinGridStore = new SkinGridStore();
  var args = Array.prototype.slice.call(arguments);
  args.unshift(this);
  skinGridStore._construct_args = args;
  return skinGridStore;
}