Socket
Socket
Sign inDemoInstall

caminte

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caminte - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

120

lib/adapters/mongodb.js

@@ -7,2 +7,3 @@ /**

var mongodb = safeRequire('mongodb');
var mongoClient = mongodb.MongoClient;
var ObjectID = mongodb.ObjectID;

@@ -51,2 +52,5 @@ var url = require('url');

s.database = s.database || process.env.USER || 'test';
if (!s.url) {
s.url = 'mongodb://' + s.host + ':' + s.port + '/' + s.database;
}
}

@@ -60,31 +64,18 @@

function MongoDB(s, schema, callback) {
var i, n;
this.name = 'mongodb';
this._models = {};
this.collections = {};
this.schema = schema;
this.s = s;
var self = this;
self.name = 'mongodb';
self._models = {};
self._db = null;
self.collections = {};
self.schema = schema;
self.s = s;
var server;
if (s.rs) {
var sets = [];
for (i = 0, n = s.hosts.length; i < n; i++) {
sets.push(new mongodb.Server(s.hosts[i], s.ports[i], {auto_reconnect: true}));
}
server = new mongodb.ReplSet(sets, {rs_name: s.rs});
} else {
server = new mongodb.Server(s.host, s.port, {});
}
new mongodb.Db(s.database, server, {safe: s.safe}).open(function (err, client) {
if (err) {
throw err;
}
this.client = client;
this.schema = schema;
this.connection()
.then(callback);
mongoClient.connect(s.url, function (err, client) {
if (err) { console.log(err); }
self.db = client.db(s.database);
self.client = client;
self.schema = schema;
self.connection()
.then(callback)
.catch(callback);
}.bind(this));

@@ -95,4 +86,3 @@ }

var t = this;
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
if (t.s.username && t.s.password) {

@@ -109,3 +99,3 @@ t.client.authenticate(t.s.username, t.s.password, function (err, result) {

t.schema.client = t.client;
setImmediate(resolve);
resolve();
}

@@ -116,7 +106,8 @@ });

MongoDB.prototype.define = function (descr) {
if (!descr.settings)
var self = this;
if (!descr.settings) {
descr.settings = {};
var self = this;
this._models[descr.model.modelName] = descr;
this.connection().then(function() {
}
self._models[descr.model.modelName] = descr;
self.connection().then(function (db) {
Object.keys(descr.properties).forEach(function (k) {

@@ -130,6 +121,12 @@ if (typeof descr.properties[k].index !== 'undefined' || typeof descr.properties[k].unique !== 'undefined') {

}
self.collection(descr.model.modelName).ensureIndex(fields, params);
if (db) {
self.db = db;
}
self.ensureIndex(descr.model.modelName, fields, params);
}
});
});
})
.catch(function (err) {
console.log('define err:', self.db, err);
});
};

@@ -143,16 +140,14 @@

var collection = this._models[name].settings.collection || name;
if (this.client.collection) {
return this.client.collection(collection);
} else {
if (!this.collections[collection]) {
this.collections[collection] = new mongodb.Collection(this.client, collection);
}
return this.collections[collection];
if (!this.collections[collection] && this.db) {
this.collections[collection] = this.db.collection(collection);
}
return this.collections[collection];
};
MongoDB.prototype.ensureIndex = function (model, fields, params, callback) {
this.collection(model).ensureIndex(fields, params);
return callback(null);
var collection = this.collection(model);
if (collection && collection.ensureIndex) {
collection.ensureIndex(fields, params);
}
return callback && callback(null);
};

@@ -175,3 +170,3 @@

id = getObjectId(id);
this.collection(model).update({_id: id}, data, function (err) {
this.collection(model).update({ _id: id }, data, function (err) {
callback(err);

@@ -199,3 +194,3 @@ });

}
this.collection(model).update(filter, {'$set': data}, {w: 1, multi: true}, function (err) {
this.collection(model).update(filter, { '$set': data }, { w: 1, multi: true }, function (err) {
return callback && callback(err, 0);

@@ -207,3 +202,3 @@ });

id = getObjectId(id);
this.collection(model).findOne({_id: id}, function (err, data) {
this.collection(model).findOne({ _id: id }, function (err, data) {
return callback && callback(err, !err && data);

@@ -216,3 +211,3 @@ });

id = getObjectId(id);
self.collection(model).findOne({_id: id}, function (err, data) {
self.collection(model).findOne({ _id: id }, function (err, data) {
if (data) {

@@ -227,13 +222,14 @@ data.id = id;

MongoDB.prototype.updateOrCreate = function updateOrCreate(model, data, callback) {
var adapter = this;
if (!data.id)
return this.create(data, callback);
this.find(model, data.id, function (err, inst) {
var self = this;
if (!data.id) {
return self.create(data, callback);
}
self.find(model, data.id, function (err, inst) {
if (err)
return callback(err);
if (inst) {
adapter.updateAttributes(model, data.id, data, callback);
self.updateAttributes(model, data.id, data, callback);
} else {
delete data.id;
adapter.create(model, data, function (err, id) {
self.create(model, data, function (err, id) {
if (err)

@@ -255,3 +251,3 @@ return callback(err);

id = getObjectId(id);
this.collection(model).remove({_id: id}, callback);
this.collection(model).remove({ _id: id }, callback);
};

@@ -272,3 +268,3 @@

}
var self = this, cursor = this.collection(model).find(query);
var self = this, cursor = self.collection(model).find(query);

@@ -325,3 +321,3 @@ if (filter.order) {

id = getObjectId(id);
this.collection(model).findAndModify({_id: id}, [['_id', 'asc']], {$set: data}, {}, callback);
this.collection(model).findAndModify({ _id: id }, [['_id', 'asc']], { $set: data }, {}, callback);
};

@@ -389,3 +385,3 @@

if (spec === 'between') {
query[k] = {$gte: cond[0], $lte: cond[1]};
query[k] = { $gte: cond[0], $lte: cond[1] };
} else {

@@ -403,3 +399,3 @@ query[k] = {};

if (cond === null) {
query[k] = {$type: 10};
query[k] = { $type: 10 };
} else {

@@ -406,0 +402,0 @@ query[k] = cond;

@@ -411,3 +411,3 @@ /**

'is_nullable as "Null", column_default as "Default" ' +
'FROM information_schema.COLUMNS WHERE table_name = "' + self.table(model) + '"';
'FROM information_schema.COLUMNS WHERE table_name = "\'' + self.table(model) + '\'';
self.client.query(sql, function (err, fields) {

@@ -414,0 +414,0 @@ if(err){

{
"name": "caminte",
"description": "ORM for every database: redis, mysql, neo4j, mongodb, rethinkdb, postgres, sqlite, tingodb",
"version": "0.4.0",
"version": "0.4.1",
"author": {

@@ -99,38 +99,44 @@ "name": "Aleksej Gordejev",

"scripts": {
"test": "make test"
"test": "make test",
"test:mysql": "cross-env CAMINTE_DRIVER=mysql _mocha --timeout 3000 -r should -R spec --exit",
"test:sqlite": "cross-env CAMINTE_DRIVER=sqlite _mocha --timeout 3000 -r should -R spec --exit",
"test:postgres": "cross-env CAMINTE_DRIVER=postgres _mocha --timeout 3000 -r should -R spec --exit",
"test:redis": "cross-env CAMINTE_DRIVER=redis _mocha --timeout 3000 -r should -R spec --exit",
"test:mongo": "cross-env CAMINTE_DRIVER=mongo _mocha --timeout 3000 -r should -R spec --exit"
},
"engines": {
"node": ">=0.10",
"npm": ">=1.0"
"node": ">=4",
"npm": ">=2"
},
"dependencies": {
"bluebird": "^3.4.6",
"uuid": "^3.0.1"
"bluebird": "^3.5.1",
"uuid": "^3.2.1"
},
"devDependencies": {
"arangojs": "4.2.0 - 4.4.0",
"async": "latest",
"cassandra-driver": ">=2.1.0",
"coffee-script": "*",
"semicov": "latest",
"should": "latest",
"generic-pool": "latest",
"cradle": ">= 0.6.0",
"felix-couchdb": ">= 1.0.0",
"istanbul": "latest",
"async": "^2.6.0",
"cassandra-driver": "^3.5.0",
"coffee-script": "^1.12.7",
"cradle": "^0.7.1",
"cross-env": "5.1.4",
"felix-couchdb": "^1.0.8",
"generic-pool": "^3.4.2",
"istanbul": "^0.4.5",
"jshint": "2.x",
"mocha": "latest",
"moment": "latest",
"mongodb": ">= 2.0.0",
"mongoose": ">= 3.0.0",
"mysql": ">= 2.0.0",
"mocha": "^5.1.1",
"moment": "^2.22.1",
"mongodb": "^3.0.7",
"mongoose": "^5.0.17",
"mysql": "^2.15.0",
"node-neo4j": "^2.0.3",
"pg": ">= 4.0.0",
"redis": ">= 0.12.0",
"rethinkdb": ">= 1.16",
"riak-js": ">= 1.0.0",
"sqlite3": "^3.1.1",
"underscore": "latest"
"pg": "^7.4.1",
"redis": "^2.8.0",
"rethinkdb": "^2.3.3",
"riak-js": "^1.1.0",
"semicov": "^0.2.0",
"should": "^13.2.1",
"sqlite3": "^4.0.0",
"underscore": "^1.9.0"
},
"optionalDependencies": {}
}

@@ -81,2 +81,6 @@ [![Build Status](https://travis-ci.org/biggora/caminte.svg?branch=master)](https://travis-ci.org/biggora/caminte)

Create Tables:
After created models, you can enable env `AUTOUPDATE` to true, when app initialize, this try create tables structures on database.
Create model and routes:

@@ -83,0 +87,0 @@

@@ -44,3 +44,3 @@ /**

driver : 'postgres',
host : gitlab ? 'postgres' : '192.168.99.100',
host : gitlab ? 'postgres' : '127.0.0.1',
port : '5432',

@@ -47,0 +47,0 @@ username : 'test',

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