Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added debug functionality and removed console.log #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions dist/diskdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ Object.defineProperty(exports, "__esModule", {

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

//local modules


var _path = require('path');

var _chalk = require('chalk');
Expand All @@ -33,6 +30,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var debug = require('debug')('diskdb');

//local modules

var DiskDB = function () {
function DiskDB() {
_classCallCheck(this, DiskDB);
Expand All @@ -43,13 +44,12 @@ var DiskDB = function () {
value: function connect(path, collections) {
if ((0, _util.isValidPath)(path)) {
this._db = { path: path };
console.log((0, _chalk.green)('Successfully connected to : ' + path));
debug('Successfully connected to : ' + path);
if (collections) {
this.loadCollections(collections);
}
} else {
console.log((0, _chalk.red)('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again'));
return false;
throw (0, _chalk.red)('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again');
}
return this;
}
Expand All @@ -59,8 +59,7 @@ var DiskDB = function () {
var _this = this;

if (!this._db) {
console.log((0, _chalk.red)('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');'));
return false;
throw (0, _chalk.red)('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');');
}
if (Array.isArray(collections)) {
collections.forEach(function (collection) {
Expand All @@ -75,7 +74,7 @@ var DiskDB = function () {
_this[collectionName] = new _collection2.default(_this, collectionName);
});
} else {
console.log((0, _chalk.red)('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']'));
throw (0, _chalk.red)('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']');
}
return this;
}
Expand Down
13 changes: 6 additions & 7 deletions lib/diskdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
'use strict';

// global modules
const debug = require('debug')('diskdb');
import { join } from 'path';
import { red as e, green as s } from 'chalk';
import { red as e } from 'chalk';

//local modules
import { isValidPath, writeToFile } from './util';
Expand All @@ -21,21 +22,19 @@ export default class DiskDB {
connect(path, collections) {
if (isValidPath(path)) {
this._db = { path };
console.log(s('Successfully connected to : ' + path));
debug('Successfully connected to : ' + path);
if (collections) {
this.loadCollections(collections);
}
} else {
console.log(e('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again'));
return false;
throw(e('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again'));
}
return this;
}

loadCollections(collections) {
if (!this._db) {
console.log(e('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');'));
return false;
throw(e('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');'));
}
if (Array.isArray(collections)) {
collections.forEach(collection => {
Expand All @@ -50,7 +49,7 @@ export default class DiskDB {
this[collectionName] = new Collection(this, collectionName);
});
} else {
console.log(e('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']'));
throw(e('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']'));
}
return this;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"chalk": "^0.4.0",
"debug": "^3.1.0",
"merge": "^1.1.3",
"uuid": "^3.0.0"
},
Expand Down