forked from otterthecat/mongonaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.03 KB
/
index.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
'use strict';
let exec = require('child_process').exec;
let defaults = require('./lib/defaults');
let query = require('./lib/query');
let helpers = require('./lib/helpers');
let runDbAction = helpers.runQueryAction;
let getDbQuery = helpers.getDbQuery;
let Mongonaut = function (options) {
this.config = Object.assign(defaults(), options);
this.exec = exec;
this.query = query;
this.runDbAction = runDbAction.bind(this);
};
Mongonaut.prototype = {
'import': function (files) {
return this.runDbAction(getDbQuery('import'), files);
},
'export': function (collections) {
return this.runDbAction(getDbQuery('export'), collections);
},
'set': function () {
if (typeof arguments[0] === 'object') {
this.config = Object.assign(this.config, arguments[0]);
return this;
}
else if (typeof arguments[0] === 'string' && typeof arguments[1] === 'string') {
this.config[arguments[0]] = arguments[1];
return this;
}
return new Error('Invalid argument(s)');
}
};
module.exports = Mongonaut;