Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

db; rename collection -> col etc

  • Loading branch information...
commit 550819b50417ce8c603c7e4bbecc35d0af507732 1 parent 20731e7
@aheckmann authored
Showing with 21 additions and 5 deletions.
  1. +21 −5 lib/db.js
View
26 lib/db.js
@@ -34,7 +34,7 @@ function createConstructor (db) {
var collections = [];
function DB () {
- this.collections();
+ this.cols(false);
}
/**
@@ -127,7 +127,7 @@ function createConstructor (db) {
* Access a collection
*/
- ;(DB.prototype.collection = function (name, opts) {
+ ;(DB.prototype.col = function (name, opts) {
if (this[name]) {
return this[name];
}
@@ -146,7 +146,7 @@ function createConstructor (db) {
* @param {Function} [cb]
*/
- ;(DB.prototype.createCollection = function (name, opts, cb) {
+ ;(DB.prototype.createCol = function (name, opts, cb) {
if ('function' == typeof opts) {
cb = opts;
opts = {};
@@ -183,12 +183,20 @@ function createConstructor (db) {
/**
* Refresh and return the list of collections on this database
*
- * @param {Function} cb
+ * @param {Boolean} [print] if the collection names should be printed
+ * @param {Function} [cb] passed any error and the result array
*/
- ;(DB.prototype.collections = function (cb) {
+ ;(DB.prototype.cols = function (print, cb) {
var self = this;
+ if ('function' == typeof print) {
+ cb = print;
+ print = false;
+ }
+
+ if (undefined == print) print = true
+
db.collectionNames({ namesOnly: true }, function (err, names) {
if (err) {
if (cb) return cb(err);
@@ -221,6 +229,14 @@ function createConstructor (db) {
});
if (cb) return cb(err, names);
+
+ if (print) {
+ console.log();
+ names.forEach(function (name) {
+ log(name);
+ })
+ global.repl.displayPrompt();
+ }
});
}).help = help("Retreives an array of collection names in the db")
Please sign in to comment.
Something went wrong with that request. Please try again.