Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

modli-mongo

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modli-mongo - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

docker/startup.sh

259

build/index.js

@@ -1,1 +0,258 @@

"use strict";
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
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; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _bluebird = require('bluebird');
var _bluebird2 = _interopRequireDefault(_bluebird);
var _events = require('events');
var _mongodb = require('mongodb');
var event = new _events.EventEmitter();
/**
* @class mongo
*/
var _default = (function () {
/**
* Handles setup of connection
* @param {Object|String} config The db config obejct or connection string
* @property {String} config.host
* @property {Number} config.port
* @property {String} config.database
* @property {String} config.username
* @property {String} config.password
*/
function _default(config) {
var _this = this;
_classCallCheck(this, _default);
var connStr = undefined;
this.db = false;
if (typeof config === 'string') {
// If full conn string is passed
connStr = config;
} else {
// Build from object
connStr = 'mongodb://' + config.username + ':' + config.password + '@' + config.host + ':' + config.port + '/' + config.database;
}
// Create connection
_mongodb.MongoClient.connect(connStr, function (err, db) {
/* istanbul ignore if */
if (err) {
throw new Error(err);
} else {
// Set instance db
_this.db = db;
// Emit when conn established
event.emit('dbInit');
return db;
}
});
}
/**
* Ensures connection established or waits for emit
* @returns {Object} promise
*/
_createClass(_default, [{
key: 'checkConn',
value: function checkConn() {
var _this2 = this;
return new _bluebird2['default'](function (resolve) {
/* istanbul ignore if */
if (!_this2.db) {
event.on('dbInit', function () {
resolve();
});
} else {
resolve();
}
});
}
/**
* Executes mongo commands after ensuring established connection
* @param {String} command The command to execute
* @param {*} ...params Spread of args to command
* @returns {Object} promise
*/
}, {
key: 'execute',
value: function execute(command) {
var _this3 = this;
for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
params[_key - 1] = arguments[_key];
}
return new _bluebird2['default'](function (resolve, reject) {
// Ensure (or wait for) connection
_this3.checkConn().then(function () {
// Execute
try {
var coll = _this3.db.collection(_this3.collection);
if (command === 'find') {
// Find needs `toArray`
resolve(coll.find(params[0]).toArray());
} else {
// All other commands
resolve(coll[command].apply(coll, params));
}
} catch (e) {
reject(e);
}
});
});
}
}, {
key: 'createCollection',
value: function createCollection(options) {
var _this4 = this;
return new _bluebird2['default'](function (resolve) {
// Ensure (or wait for) connection
_this4.checkConn().then(function () {
resolve(_this4.db.createCollection(_this4.collection, options));
});
});
}
/**
* Creates a new record in the collection set
* @param {Object} body The object to insert
* @param {String|Number|Boolean} [version] The model version to use
* @returns {Object} promise
*/
}, {
key: 'create',
value: function create(body) {
var _this5 = this;
var version = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
return new _bluebird2['default'](function (resolve, reject) {
var validationErrors = _this5.validate(body, version);
if (validationErrors) {
reject(validationErrors);
} else {
_this5.execute('insert', body).then(function (res) {
resolve(res.ops);
})['catch'](function (err) {
reject(err);
});
}
});
}
/**
* Reads record(s) from the collection based on query
* @param {Object} [query] The query to execute
* @param {String|Number|Boolean} [version]
* @returns {Object} promise
*/
}, {
key: 'read',
value: function read() {
var _this6 = this;
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var version = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
return new _bluebird2['default'](function (resolve, reject) {
_this6.execute('find', query).then(function (res) {
var tmp = [];
res.forEach(function (rec) {
tmp.push(_this6.sanitize(rec, version));
});
resolve(tmp);
})['catch'](function (err) {
reject(err);
});
});
}
/**
* Updates record(s) from the collection based on query and body
* @param {Object} [query] The query to execute
* @param {Object} body The record property(ies) to update
* @param {String|Number|Boolean} [version]
* @returns {Object} promise
*/
}, {
key: 'update',
value: function update() {
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _this7 = this;
var body = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var version = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
return new _bluebird2['default'](function (resolve, reject) {
var validationErrors = _this7.validate(body, version);
if (validationErrors) {
reject(validationErrors);
} else {
_this7.execute('update', query, { $set: body }).then(function (res) {
resolve(res.result);
})['catch'](function (err) {
reject(err);
});
}
});
}
/**
* Deletes record(s) from the collection based on query
* @param {Object} query The query to execute
* @returns {Object} promise
*/
}, {
key: 'delete',
value: function _delete(query) {
var _this8 = this;
return new _bluebird2['default'](function (resolve, reject) {
_this8.execute('remove', query).then(function (res) {
resolve(res.result);
})['catch'](function (err) {
reject(err);
});
});
}
/**
* Extends adapter by adding new method
* @memberof nedb
* @param {String} name The name of the method
* @param {Function} fn The method to add
*/
}, {
key: 'extend',
value: function extend(name, fn) {
this[name] = fn.bind(this);
}
}]);
return _default;
})();
exports['default'] = _default;
module.exports = exports['default'];

2

coverage/coverage.json

@@ -1,1 +0,1 @@

{"/home/fluidbyte/workspace/ta/modli/nedb/src/index.js":{"path":"/home/fluidbyte/workspace/ta/modli/nedb/src/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":3,"11":3,"12":3,"13":3,"14":2,"15":1,"16":1,"17":1,"18":1,"19":1,"20":1,"21":1,"22":1,"23":0,"24":1,"25":1,"26":1,"27":1,"28":1},"b":{"1":[3,0],"2":[3,0],"3":[2,1],"4":[1,0],"5":[1,0],"6":[0,1]},"f":{"1":1,"2":3,"3":3,"4":1,"5":1,"6":1,"7":1,"8":1},"fnMap":{"1":{"name":"(anonymous_1)","line":20,"loc":{"start":{"line":20,"column":14},"end":{"line":20,"column":29}}},"2":{"name":"(anonymous_2)","line":32,"loc":{"start":{"line":32,"column":14},"end":{"line":32,"column":30}}},"3":{"name":"(anonymous_3)","line":38,"loc":{"start":{"line":38,"column":21},"end":{"line":38,"column":48}}},"4":{"name":"(anonymous_4)","line":54,"loc":{"start":{"line":54,"column":12},"end":{"line":54,"column":29}}},"5":{"name":"(anonymous_5)","line":66,"loc":{"start":{"line":66,"column":14},"end":{"line":66,"column":37}}},"6":{"name":"(anonymous_6)","line":72,"loc":{"start":{"line":72,"column":21},"end":{"line":72,"column":48}}},"7":{"name":"(anonymous_7)","line":88,"loc":{"start":{"line":88,"column":17},"end":{"line":88,"column":34}}},"8":{"name":"(anonymous_8)","line":98,"loc":{"start":{"line":98,"column":14},"end":{"line":98,"column":34}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":5,"column":3}},"2":{"start":{"line":6,"column":0},"end":{"line":6,"column":34}},"3":{"start":{"line":7,"column":0},"end":{"line":7,"column":32}},"4":{"start":{"line":12,"column":0},"end":{"line":12,"column":14}},"5":{"start":{"line":14,"column":0},"end":{"line":14,"column":20}},"6":{"start":{"line":20,"column":0},"end":{"line":23,"column":2}},"7":{"start":{"line":21,"column":2},"end":{"line":21,"column":53}},"8":{"start":{"line":22,"column":2},"end":{"line":22,"column":14}},"9":{"start":{"line":32,"column":0},"end":{"line":46,"column":2}},"10":{"start":{"line":33,"column":2},"end":{"line":33,"column":91}},"11":{"start":{"line":36,"column":2},"end":{"line":36,"column":54}},"12":{"start":{"line":38,"column":2},"end":{"line":45,"column":5}},"13":{"start":{"line":40,"column":4},"end":{"line":44,"column":5}},"14":{"start":{"line":41,"column":6},"end":{"line":41,"column":31},"skip":true},"15":{"start":{"line":43,"column":6},"end":{"line":43,"column":41}},"16":{"start":{"line":54,"column":0},"end":{"line":56,"column":2}},"17":{"start":{"line":55,"column":2},"end":{"line":55,"column":34}},"18":{"start":{"line":66,"column":0},"end":{"line":80,"column":2}},"19":{"start":{"line":67,"column":2},"end":{"line":67,"column":91}},"20":{"start":{"line":70,"column":2},"end":{"line":70,"column":54}},"21":{"start":{"line":72,"column":2},"end":{"line":79,"column":5}},"22":{"start":{"line":74,"column":4},"end":{"line":78,"column":5}},"23":{"start":{"line":75,"column":6},"end":{"line":75,"column":31},"skip":true},"24":{"start":{"line":77,"column":6},"end":{"line":77,"column":75}},"25":{"start":{"line":88,"column":0},"end":{"line":90,"column":2}},"26":{"start":{"line":89,"column":2},"end":{"line":89,"column":53}},"27":{"start":{"line":98,"column":0},"end":{"line":100,"column":2}},"28":{"start":{"line":99,"column":2},"end":{"line":99,"column":29}}},"branchMap":{"1":{"line":33,"type":"cond-expr","locations":[{"start":{"line":33,"column":70},"end":{"line":33,"column":75}},{"start":{"line":33,"column":78},"end":{"line":33,"column":90}}]},"2":{"line":33,"type":"binary-expr","locations":[{"start":{"line":33,"column":16},"end":{"line":33,"column":37}},{"start":{"line":33,"column":41},"end":{"line":33,"column":67}}]},"3":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":4},"end":{"line":40,"column":4},"skip":true},{"start":{"line":40,"column":4},"end":{"line":40,"column":4}}]},"4":{"line":67,"type":"cond-expr","locations":[{"start":{"line":67,"column":70},"end":{"line":67,"column":75}},{"start":{"line":67,"column":78},"end":{"line":67,"column":90}}]},"5":{"line":67,"type":"binary-expr","locations":[{"start":{"line":67,"column":16},"end":{"line":67,"column":37}},{"start":{"line":67,"column":41},"end":{"line":67,"column":67}}]},"6":{"line":74,"type":"if","locations":[{"start":{"line":74,"column":4},"end":{"line":74,"column":4},"skip":true},{"start":{"line":74,"column":4},"end":{"line":74,"column":4}}]}}}}
{"/home/fluidbyte/workspace/ta/modli/mongo/src/index.js":{"path":"/home/fluidbyte/workspace/ta/modli/mongo/src/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":8,"6":8,"7":8,"8":8,"9":8,"10":8,"11":1,"12":1,"13":1,"14":1,"15":0,"16":1,"17":1,"18":1,"19":1,"20":3,"21":0,"22":1,"23":1,"24":1,"25":1,"26":1,"27":1,"28":1,"29":3,"30":3,"31":3,"32":3,"33":3,"34":1,"35":2,"36":3,"37":3,"38":0,"39":3,"40":3,"41":3,"42":1,"43":14,"44":14,"45":14,"46":1,"47":3,"48":13,"49":12,"50":12,"51":12,"52":12,"53":12,"54":12,"55":12,"56":12,"57":3,"58":9,"59":3,"60":2,"61":2,"62":2,"63":2,"64":3,"65":3,"66":3,"67":3,"68":3,"69":1,"70":2,"71":1,"72":1,"73":3,"74":3,"75":3,"76":3,"77":3,"78":2,"79":2,"80":10,"81":2,"82":1,"83":3,"84":3,"85":3,"86":3,"87":3,"88":3,"89":3,"90":1,"91":2,"92":1,"93":1,"94":2,"95":2,"96":2,"97":1,"98":1,"99":1,"100":1,"101":1,"102":1},"b":{"1":[8,8],"2":[8,0],"3":[1,0],"4":[0,1],"5":[0,1],"6":[1,1],"7":[0,3],"8":[1,2],"9":[0,3],"10":[1,13],"11":[3,9],"12":[2,1],"13":[3,1],"14":[1,2],"15":[1,2],"16":[3,2],"17":[2,1],"18":[3,1],"19":[0,3],"20":[3,3],"21":[0,3],"22":[3,3],"23":[3,0],"24":[3,0],"25":[1,2]},"f":{"1":1,"2":1,"3":1,"4":1,"5":3,"6":1,"7":3,"8":3,"9":14,"10":14,"11":3,"12":12,"13":12,"14":12,"15":2,"16":2,"17":2,"18":3,"19":3,"20":1,"21":1,"22":3,"23":3,"24":2,"25":10,"26":1,"27":3,"28":3,"29":1,"30":1,"31":2,"32":2,"33":1,"34":1,"35":1},"fnMap":{"1":{"name":"(anonymous_1)","line":8,"loc":{"start":{"line":8,"column":20},"end":{"line":8,"column":32}},"skip":true},"2":{"name":"defineProperties","line":8,"loc":{"start":{"line":8,"column":34},"end":{"line":8,"column":75}},"skip":true},"3":{"name":"(anonymous_3)","line":8,"loc":{"start":{"line":8,"column":358},"end":{"line":8,"column":406}},"skip":true},"4":{"name":"_interopRequireDefault","line":12,"loc":{"start":{"line":12,"column":0},"end":{"line":12,"column":37}},"skip":true},"5":{"name":"_classCallCheck","line":16,"loc":{"start":{"line":16,"column":0},"end":{"line":16,"column":48}},"skip":true},"6":{"name":"(anonymous_6)","line":32,"loc":{"start":{"line":32,"column":16},"end":{"line":32,"column":28}}},"7":{"name":"_default","line":44,"loc":{"start":{"line":44,"column":2},"end":{"line":44,"column":28}}},"8":{"name":"(anonymous_8)","line":61,"loc":{"start":{"line":61,"column":42},"end":{"line":61,"column":61}}},"9":{"name":"checkConn","line":82,"loc":{"start":{"line":82,"column":11},"end":{"line":82,"column":32}}},"10":{"name":"(anonymous_10)","line":87,"loc":{"start":{"line":87,"column":39},"end":{"line":87,"column":58}}},"11":{"name":"(anonymous_11)","line":90,"loc":{"start":{"line":90,"column":29},"end":{"line":90,"column":41}},"skip":true},"12":{"name":"execute","line":107,"loc":{"start":{"line":107,"column":11},"end":{"line":107,"column":37}}},"13":{"name":"(anonymous_13)","line":116,"loc":{"start":{"line":116,"column":39},"end":{"line":116,"column":66}}},"14":{"name":"(anonymous_14)","line":118,"loc":{"start":{"line":118,"column":32},"end":{"line":118,"column":44}}},"15":{"name":"createCollection","line":137,"loc":{"start":{"line":137,"column":11},"end":{"line":137,"column":46}}},"16":{"name":"(anonymous_16)","line":142,"loc":{"start":{"line":142,"column":39},"end":{"line":142,"column":66}}},"17":{"name":"(anonymous_17)","line":144,"loc":{"start":{"line":144,"column":32},"end":{"line":144,"column":44}}},"18":{"name":"create","line":158,"loc":{"start":{"line":158,"column":11},"end":{"line":158,"column":33}}},"19":{"name":"(anonymous_19)","line":165,"loc":{"start":{"line":165,"column":39},"end":{"line":165,"column":66}}},"20":{"name":"(anonymous_20)","line":170,"loc":{"start":{"line":170,"column":46},"end":{"line":170,"column":61}}},"21":{"name":"(anonymous_21)","line":172,"loc":{"start":{"line":172,"column":22},"end":{"line":172,"column":37}}},"22":{"name":"read","line":187,"loc":{"start":{"line":187,"column":11},"end":{"line":187,"column":27}}},"23":{"name":"(anonymous_23)","line":195,"loc":{"start":{"line":195,"column":39},"end":{"line":195,"column":66}}},"24":{"name":"(anonymous_24)","line":196,"loc":{"start":{"line":196,"column":43},"end":{"line":196,"column":58}}},"25":{"name":"(anonymous_25)","line":198,"loc":{"start":{"line":198,"column":22},"end":{"line":198,"column":37}}},"26":{"name":"(anonymous_26)","line":202,"loc":{"start":{"line":202,"column":20},"end":{"line":202,"column":35}}},"27":{"name":"update","line":217,"loc":{"start":{"line":217,"column":11},"end":{"line":217,"column":29}}},"28":{"name":"(anonymous_28)","line":226,"loc":{"start":{"line":226,"column":39},"end":{"line":226,"column":66}}},"29":{"name":"(anonymous_29)","line":231,"loc":{"start":{"line":231,"column":63},"end":{"line":231,"column":78}}},"30":{"name":"(anonymous_30)","line":233,"loc":{"start":{"line":233,"column":22},"end":{"line":233,"column":37}}},"31":{"name":"_delete","line":247,"loc":{"start":{"line":247,"column":11},"end":{"line":247,"column":35}}},"32":{"name":"(anonymous_32)","line":252,"loc":{"start":{"line":252,"column":39},"end":{"line":252,"column":66}}},"33":{"name":"(anonymous_33)","line":253,"loc":{"start":{"line":253,"column":45},"end":{"line":253,"column":60}}},"34":{"name":"(anonymous_34)","line":255,"loc":{"start":{"line":255,"column":20},"end":{"line":255,"column":35}}},"35":{"name":"extend","line":269,"loc":{"start":{"line":269,"column":11},"end":{"line":269,"column":37}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":5,"column":3}},"2":{"start":{"line":8,"column":0},"end":{"line":8,"column":566},"skip":true},"3":{"start":{"line":8,"column":34},"end":{"line":8,"column":350},"skip":true},"4":{"start":{"line":8,"column":77},"end":{"line":8,"column":348},"skip":true},"5":{"start":{"line":8,"column":118},"end":{"line":8,"column":144},"skip":true},"6":{"start":{"line":8,"column":145},"end":{"line":8,"column":200},"skip":true},"7":{"start":{"line":8,"column":201},"end":{"line":8,"column":232},"skip":true},"8":{"start":{"line":8,"column":233},"end":{"line":8,"column":287},"skip":true},"9":{"start":{"line":8,"column":260},"end":{"line":8,"column":287},"skip":true},"10":{"start":{"line":8,"column":288},"end":{"line":8,"column":346},"skip":true},"11":{"start":{"line":8,"column":351},"end":{"line":8,"column":560},"skip":true},"12":{"start":{"line":8,"column":408},"end":{"line":8,"column":476},"skip":true},"13":{"start":{"line":8,"column":424},"end":{"line":8,"column":476},"skip":true},"14":{"start":{"line":8,"column":477},"end":{"line":8,"column":537},"skip":true},"15":{"start":{"line":8,"column":494},"end":{"line":8,"column":537},"skip":true},"16":{"start":{"line":8,"column":538},"end":{"line":8,"column":557},"skip":true},"17":{"start":{"line":12,"column":0},"end":{"line":12,"column":97},"skip":true},"18":{"start":{"line":12,"column":39},"end":{"line":12,"column":95},"skip":true},"19":{"start":{"line":16,"column":0},"end":{"line":16,"column":153},"skip":true},"20":{"start":{"line":16,"column":50},"end":{"line":16,"column":151},"skip":true},"21":{"start":{"line":16,"column":92},"end":{"line":16,"column":149},"skip":true},"22":{"start":{"line":18,"column":0},"end":{"line":18,"column":36}},"23":{"start":{"line":20,"column":0},"end":{"line":20,"column":51}},"24":{"start":{"line":22,"column":0},"end":{"line":22,"column":32}},"25":{"start":{"line":24,"column":0},"end":{"line":24,"column":34}},"26":{"start":{"line":26,"column":0},"end":{"line":26,"column":39}},"27":{"start":{"line":32,"column":0},"end":{"line":275,"column":5}},"28":{"start":{"line":44,"column":2},"end":{"line":73,"column":3}},"29":{"start":{"line":47,"column":4},"end":{"line":47,"column":21},"skip":true},"30":{"start":{"line":49,"column":4},"end":{"line":49,"column":36}},"31":{"start":{"line":51,"column":4},"end":{"line":51,"column":28}},"32":{"start":{"line":52,"column":4},"end":{"line":52,"column":20}},"33":{"start":{"line":53,"column":4},"end":{"line":59,"column":5}},"34":{"start":{"line":55,"column":6},"end":{"line":55,"column":23}},"35":{"start":{"line":58,"column":6},"end":{"line":58,"column":135}},"36":{"start":{"line":61,"column":4},"end":{"line":72,"column":7}},"37":{"start":{"line":63,"column":6},"end":{"line":71,"column":7}},"38":{"start":{"line":64,"column":8},"end":{"line":64,"column":29},"skip":true},"39":{"start":{"line":67,"column":8},"end":{"line":67,"column":22}},"40":{"start":{"line":69,"column":8},"end":{"line":69,"column":29}},"41":{"start":{"line":70,"column":8},"end":{"line":70,"column":18}},"42":{"start":{"line":80,"column":2},"end":{"line":272,"column":6}},"43":{"start":{"line":85,"column":6},"end":{"line":85,"column":24},"skip":true},"44":{"start":{"line":87,"column":6},"end":{"line":96,"column":9}},"45":{"start":{"line":89,"column":8},"end":{"line":95,"column":9}},"46":{"start":{"line":90,"column":10},"end":{"line":92,"column":13},"skip":true},"47":{"start":{"line":91,"column":12},"end":{"line":91,"column":22},"skip":true},"48":{"start":{"line":94,"column":10},"end":{"line":94,"column":20}},"49":{"start":{"line":110,"column":6},"end":{"line":110,"column":24},"skip":true},"50":{"start":{"line":112,"column":6},"end":{"line":114,"column":7}},"51":{"start":{"line":113,"column":8},"end":{"line":113,"column":43}},"52":{"start":{"line":116,"column":6},"end":{"line":133,"column":9}},"53":{"start":{"line":118,"column":8},"end":{"line":132,"column":11}},"54":{"start":{"line":120,"column":10},"end":{"line":131,"column":11}},"55":{"start":{"line":121,"column":12},"end":{"line":121,"column":63}},"56":{"start":{"line":122,"column":12},"end":{"line":128,"column":13}},"57":{"start":{"line":124,"column":14},"end":{"line":124,"column":54}},"58":{"start":{"line":127,"column":14},"end":{"line":127,"column":57}},"59":{"start":{"line":130,"column":12},"end":{"line":130,"column":22}},"60":{"start":{"line":140,"column":6},"end":{"line":140,"column":24},"skip":true},"61":{"start":{"line":142,"column":6},"end":{"line":147,"column":9}},"62":{"start":{"line":144,"column":8},"end":{"line":146,"column":11}},"63":{"start":{"line":145,"column":10},"end":{"line":145,"column":74}},"64":{"start":{"line":161,"column":6},"end":{"line":161,"column":24},"skip":true},"65":{"start":{"line":163,"column":6},"end":{"line":163,"column":95}},"66":{"start":{"line":165,"column":6},"end":{"line":176,"column":9}},"67":{"start":{"line":166,"column":8},"end":{"line":166,"column":62}},"68":{"start":{"line":167,"column":8},"end":{"line":175,"column":9}},"69":{"start":{"line":168,"column":10},"end":{"line":168,"column":35}},"70":{"start":{"line":170,"column":10},"end":{"line":174,"column":13}},"71":{"start":{"line":171,"column":12},"end":{"line":171,"column":29}},"72":{"start":{"line":173,"column":12},"end":{"line":173,"column":24}},"73":{"start":{"line":190,"column":6},"end":{"line":190,"column":24},"skip":true},"74":{"start":{"line":192,"column":6},"end":{"line":192,"column":90}},"75":{"start":{"line":193,"column":6},"end":{"line":193,"column":95}},"76":{"start":{"line":195,"column":6},"end":{"line":205,"column":9}},"77":{"start":{"line":196,"column":8},"end":{"line":204,"column":11}},"78":{"start":{"line":197,"column":10},"end":{"line":197,"column":23}},"79":{"start":{"line":198,"column":10},"end":{"line":200,"column":13}},"80":{"start":{"line":199,"column":12},"end":{"line":199,"column":52}},"81":{"start":{"line":201,"column":10},"end":{"line":201,"column":23}},"82":{"start":{"line":203,"column":10},"end":{"line":203,"column":22}},"83":{"start":{"line":218,"column":6},"end":{"line":218,"column":90}},"84":{"start":{"line":221,"column":6},"end":{"line":221,"column":24},"skip":true},"85":{"start":{"line":223,"column":6},"end":{"line":223,"column":89}},"86":{"start":{"line":224,"column":6},"end":{"line":224,"column":95}},"87":{"start":{"line":226,"column":6},"end":{"line":237,"column":9}},"88":{"start":{"line":227,"column":8},"end":{"line":227,"column":62}},"89":{"start":{"line":228,"column":8},"end":{"line":236,"column":9}},"90":{"start":{"line":229,"column":10},"end":{"line":229,"column":35}},"91":{"start":{"line":231,"column":10},"end":{"line":235,"column":13}},"92":{"start":{"line":232,"column":12},"end":{"line":232,"column":32}},"93":{"start":{"line":234,"column":12},"end":{"line":234,"column":24}},"94":{"start":{"line":250,"column":6},"end":{"line":250,"column":24},"skip":true},"95":{"start":{"line":252,"column":6},"end":{"line":258,"column":9}},"96":{"start":{"line":253,"column":8},"end":{"line":257,"column":11}},"97":{"start":{"line":254,"column":10},"end":{"line":254,"column":30}},"98":{"start":{"line":256,"column":10},"end":{"line":256,"column":22}},"99":{"start":{"line":270,"column":6},"end":{"line":270,"column":33}},"100":{"start":{"line":274,"column":2},"end":{"line":274,"column":18}},"101":{"start":{"line":277,"column":0},"end":{"line":277,"column":30}},"102":{"start":{"line":278,"column":0},"end":{"line":278,"column":36}}},"branchMap":{"1":{"line":8,"type":"binary-expr","locations":[{"start":{"line":8,"column":169},"end":{"line":8,"column":190},"skip":true},{"start":{"line":8,"column":194},"end":{"line":8,"column":199},"skip":true}]},"2":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":233},"end":{"line":8,"column":233},"skip":true},{"start":{"line":8,"column":233},"end":{"line":8,"column":233},"skip":true}]},"3":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":408},"end":{"line":8,"column":408},"skip":true},{"start":{"line":8,"column":408},"end":{"line":8,"column":408},"skip":true}]},"4":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":477},"end":{"line":8,"column":477},"skip":true},{"start":{"line":8,"column":477},"end":{"line":8,"column":477},"skip":true}]},"5":{"line":12,"type":"cond-expr","locations":[{"start":{"line":12,"column":70},"end":{"line":12,"column":73},"skip":true},{"start":{"line":12,"column":76},"end":{"line":12,"column":94},"skip":true}]},"6":{"line":12,"type":"binary-expr","locations":[{"start":{"line":12,"column":46},"end":{"line":12,"column":49},"skip":true},{"start":{"line":12,"column":53},"end":{"line":12,"column":67},"skip":true}]},"7":{"line":16,"type":"if","locations":[{"start":{"line":16,"column":50},"end":{"line":16,"column":50},"skip":true},{"start":{"line":16,"column":50},"end":{"line":16,"column":50},"skip":true}]},"8":{"line":53,"type":"if","locations":[{"start":{"line":53,"column":4},"end":{"line":53,"column":4}},{"start":{"line":53,"column":4},"end":{"line":53,"column":4}}]},"9":{"line":63,"type":"if","locations":[{"start":{"line":63,"column":6},"end":{"line":63,"column":6},"skip":true},{"start":{"line":63,"column":6},"end":{"line":63,"column":6}}]},"10":{"line":89,"type":"if","locations":[{"start":{"line":89,"column":8},"end":{"line":89,"column":8},"skip":true},{"start":{"line":89,"column":8},"end":{"line":89,"column":8}}]},"11":{"line":122,"type":"if","locations":[{"start":{"line":122,"column":12},"end":{"line":122,"column":12}},{"start":{"line":122,"column":12},"end":{"line":122,"column":12}}]},"12":{"line":163,"type":"cond-expr","locations":[{"start":{"line":163,"column":74},"end":{"line":163,"column":79}},{"start":{"line":163,"column":82},"end":{"line":163,"column":94}}]},"13":{"line":163,"type":"binary-expr","locations":[{"start":{"line":163,"column":20},"end":{"line":163,"column":41}},{"start":{"line":163,"column":45},"end":{"line":163,"column":71}}]},"14":{"line":167,"type":"if","locations":[{"start":{"line":167,"column":8},"end":{"line":167,"column":8}},{"start":{"line":167,"column":8},"end":{"line":167,"column":8}}]},"15":{"line":192,"type":"cond-expr","locations":[{"start":{"line":192,"column":72},"end":{"line":192,"column":74}},{"start":{"line":192,"column":77},"end":{"line":192,"column":89}}]},"16":{"line":192,"type":"binary-expr","locations":[{"start":{"line":192,"column":18},"end":{"line":192,"column":39}},{"start":{"line":192,"column":43},"end":{"line":192,"column":69}}]},"17":{"line":193,"type":"cond-expr","locations":[{"start":{"line":193,"column":74},"end":{"line":193,"column":79}},{"start":{"line":193,"column":82},"end":{"line":193,"column":94}}]},"18":{"line":193,"type":"binary-expr","locations":[{"start":{"line":193,"column":20},"end":{"line":193,"column":41}},{"start":{"line":193,"column":45},"end":{"line":193,"column":71}}]},"19":{"line":218,"type":"cond-expr","locations":[{"start":{"line":218,"column":72},"end":{"line":218,"column":74}},{"start":{"line":218,"column":77},"end":{"line":218,"column":89}}]},"20":{"line":218,"type":"binary-expr","locations":[{"start":{"line":218,"column":18},"end":{"line":218,"column":39}},{"start":{"line":218,"column":43},"end":{"line":218,"column":69}}]},"21":{"line":223,"type":"cond-expr","locations":[{"start":{"line":223,"column":71},"end":{"line":223,"column":73}},{"start":{"line":223,"column":76},"end":{"line":223,"column":88}}]},"22":{"line":223,"type":"binary-expr","locations":[{"start":{"line":223,"column":17},"end":{"line":223,"column":38}},{"start":{"line":223,"column":42},"end":{"line":223,"column":68}}]},"23":{"line":224,"type":"cond-expr","locations":[{"start":{"line":224,"column":74},"end":{"line":224,"column":79}},{"start":{"line":224,"column":82},"end":{"line":224,"column":94}}]},"24":{"line":224,"type":"binary-expr","locations":[{"start":{"line":224,"column":20},"end":{"line":224,"column":41}},{"start":{"line":224,"column":45},"end":{"line":224,"column":71}}]},"25":{"line":228,"type":"if","locations":[{"start":{"line":228,"column":8},"end":{"line":228,"column":8}},{"start":{"line":228,"column":8},"end":{"line":228,"column":8}}]}}}}
{
"name": "modli-mongo",
"version": "0.0.1",
"version": "1.0.0",
"description": "Modli adapter for Mongo",

@@ -43,3 +43,4 @@ "main": "build/index.js",

"dependencies": {
"bluebird": "^2.9.34"
"bluebird": "^2.9.34",
"mongodb": "^2.0.42"
},

@@ -46,0 +47,0 @@ "pre-commit": [

@@ -5,6 +5,2 @@ [![wercker status](https://app.wercker.com/status/965720bdeb6427fcccf0323da755240b/s/master "wercker status")](https://app.wercker.com/project/bykey/965720bdeb6427fcccf0323da755240b)

> # ATTENTION: In Development
> This repository is currently in development.
# Modli - Mongo Adapter

@@ -21,29 +17,158 @@

## Usage
## Config and Usage
When defining a property which will utilize the adapter it is required that a
`collection` be supplied:
```javascript
import { model, adapter, Joi, use } from 'modli';
import { mongo } from 'modli-mongo';
import mongo from 'modli-mongo';
// Create a model
model.add({
name: 'testModel',
name: 'foo',
version: 1,
collection: 'fooCollection'
schema: {
/* ...schema properties... */
id: Joi.number().integer(),
fname: Joi.string().min(3).max(30),
lname: Joi.string().min(3).max(30),
email: Joi.string().email().min(3).max(254).required()
}
});
```
// Add adapter using NeDB
model.add({
name: 'testMongo',
Then add the adapter as per usual with the following config object structure:
```javascript
adapter.add({
name: 'mongoFoo',
source: mongo
config: {
/*...*/
host: {HOST_IP},
port: {HOST_PORT},
username: {USERNAME},
password: {PASSWORD},
database: {DATABASE}
}
});
```
const testModli = use('testModel', 'testMongo');
You can then use the adapter with a model via:
```javascript
// Use(MODEL, ADAPTER)
const mongoTest = use('foo', 'mongoFoo');
```
## Methods
The following methods exist natively on the Mongo adapter:
### `execute`
Allows for executing methods directly on the collection:
```javascript
mongoTest.execute('insert', { /*...record...*/ })
.then(/*...*/)
.catch(/*...*/);
```
### `checkConn`
Ensures (or waits for) established connection:
```javascript
mongoTest.checkConn()
.then(/*...*/);
```
*Note: the `checkConn` method is already utilized by all other methods
and only needs to be added in a case where you're extending
on or using a method of the `db` object directly.*
### `createCollection`
Creates the collection based on the model's `collection` name:
```javascript
mongoTest.createCollection()
.then(/*...*/)
.catch(/*...*/);
```
### `create`
Creates a new record based on object passed:
```javascript
mongoTest.create({
fname: 'John',
lname: 'Smith',
email: 'jsmith@gmail.com'
})
.then(/*...*/)
.catch(/*...*/);
```
### `read`
Returns records matching a query object (or all if no query specified):
```javascript
mongoTest.read({ fname: 'John' })
.then(/*...*/)
.catch(/*...*/);
```
### `update`
Updates record(s) based on query and body:
```javascript
mongoTest.update({ fname: 'John' }, {
fname: 'Bob',
email: 'bsmith@gmail.com'
})
.then(/*...*/)
.catch(/*...*/);
```
### `delete`
Deletes record(s) based on query:
```javascript
mongoTest.delete({ fname: 'John' })
.then(/*...*/)
.catch(/*...*/);
```
### `extend`
Extends the adapter to allow for custom methods:
```javascript
mongoTest.extend('myMethod', () => {
/*...*/
});
```
## Development
The Mongo adapter requires the following enviroment variables to be set for
running the tests. These should be associated with the Mongo instance running
locally.
```
MODLI_MONGO_HOST,
MODLI_MONGO_PORT,
MODLI_MONGO_USERNAME,
MODLI_MONGO_PASSWORD,
MODLI_MONGO_DATABASE
```
This repository includes a base container config for running locally which is
located in the [/docker](/docker) directory.
## Makefile and Scripts

@@ -50,0 +175,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc