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

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.1.1 to 0.1.2

.editorconfig

23

index.js

@@ -5,9 +5,12 @@ /**

var fs = require('fs');
var path = require('path');
var schema = require('./lib/schema');
var pkg = require('./package');
var abc = require('./lib/abstract-class');
var vld = require('./lib/validatable');
Schema = require('./lib/schema').Schema;
Schema = schema.Schema;
exports.Schema = Schema;
exports.AbstractClass = require('./lib/abstract-class').AbstractClass;
exports.Validatable = require('./lib/validatable').Validatable;
exports.AbstractClass = abc.AbstractClass;
exports.Validatable = vld.Validatable;
exports.__defineGetter__('BaseSQL', function () {

@@ -23,16 +26,8 @@ return require('./lib/sql');

}
// var railway = './lib/railway';
// require(railway)(rw);
};
try {
if (process.versions.node < '0.6') {
exports.version = JSON.parse(fs.readFileSync(__dirname + '/package.json')).version;
} else {
exports.version = require('./package').version;
}
} catch (e) {}
exports.version = pkg.version;
exports.__defineGetter__('test', function () {
return require('./tests/common_test');
return require('./tmp/tests/common_test');
});

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

if (inst.id) {
data.id = inst.id;
inst.trigger('update', function (updateDone) {

@@ -803,0 +804,0 @@ inst._adapter().save(modelName, inst.constructor._forDB(data), function (err) {

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

sql += ' ' + self.buildWhere(filter, self, model);
console.log(sql)
this.query(sql, function (err, affected) {

@@ -213,0 +212,0 @@ callback(err, affected);

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

if (schema.settings.socket) {
schema.client = redis.createClient(

@@ -22,5 +21,3 @@ schema.settings.socket,

);
} else if (schema.settings.url) {
var url = require('url');

@@ -31,3 +28,2 @@ var redisUrl = url.parse(schema.settings.url);

schema.settings.port = redisUrl.port;
if (redisAuth.length === 2) {

@@ -37,7 +33,5 @@ schema.settings.db = redisAuth[0];

}
}
if (!schema.client) {
schema.client = redis.createClient(

@@ -49,3 +43,2 @@ schema.settings.port,

schema.client.auth(schema.settings.password);
}

@@ -105,3 +98,2 @@

});
c[cmd].apply(c, args);

@@ -428,3 +420,3 @@ };

if (callback) {
callback(err, exists);
callback(err, exists ? true : false);
}

@@ -431,0 +423,0 @@ });

@@ -26,3 +26,3 @@ /**

s.ports = [];
uris.forEach(function(uri) {
uris.forEach(function (uri) {
var purl = url.parse(uri);

@@ -56,14 +56,26 @@ s.hosts.push(purl.hostname || 'localhost');

function connect(cb) {
r.connect({host: s.host, port: s.port, db: s.database}, function (error, client) {
if (error) {
return cb(error, null);
}
r.db(s.database).tableList().run(client, function (error) {
if (error && /database(.*)does\s+not\s+exist/i.test(error.message)) {
r.dbCreate(s.database).run(client, function (error) {
client.use(s.database);
cb(null, client);
});
} else {
client.use(s.database);
cb(null, client);
}
});
});
}
schema.adapter = new RethinkDB(s, schema);
schema.adapter.pool = gpool.Pool({
name: "caminte-rethink-pool",
create: function(cb) {
r.connect({host: s.host, port: s.port}, function(error, client) {
if (error) {
return cb(error, null);
}
cb(null, client);
});
},
destroy: function(client) {
create: connect,
destroy: function (client) {
client.close();

@@ -74,3 +86,3 @@ },

idleTimeoutMillis: 30000,
log: function(what, level) {
log: function (what, level) {
if (level === "error") {

@@ -95,7 +107,7 @@ fs.appendFile("caminte-rethink-pool.log", what + "\r\n");

RethinkDB.prototype.connect = function(cb) {
RethinkDB.prototype.connect = function (cb) {
cb(); // connection pooling handles it
};
RethinkDB.prototype.define = function(descr) {
RethinkDB.prototype.define = function (descr) {
if (!descr.settings)

@@ -108,122 +120,156 @@ descr.settings = {};

// creates tables if not exists
RethinkDB.prototype.autoupdate = function(cb) {
RethinkDB.prototype.autoupdate = function (callback) {
var self = this;
self.pool.acquire(function(error, client) {
if (error) {
throw error;
r.connect({host: self.s.host, port: self.s.port}, function (err, client) {
if (err) {
return callback && callback(err);
}
r.db(self.database).tableList().run(client, function(error, cursor) {
if (!error) {
cursor.toArray(function(error, list) {
if (error) {
throw error;
r.db(self.database).tableList().run(client, function (err, cursor) {
if (!err && cursor) {
cursor.toArray(function (err, list) {
if (err) {
return callback && callback(err);
}
async.each(Object.keys(self._models), function(model, cb2) {
var timeout = 0;
async.eachSeries(Object.keys(self._models), function (model, cb) {
var fields = self._models[model].properties;
if (list.length === 0 || list.indexOf(model) < 0) {
r.db(self.database).tableCreate(model).run(client, function(error) {
r.db(self.database).tableCreate(model).run(client, function (error) {
if (error) {
return cb2(error);
return cb(error);
}
createIndices();
timeout = 150;
process.nextTick(function() {
self.ensureIndex(model, fields, {}, cb);
});
});
} else {
createIndices();
process.nextTick(function() {
self.ensureIndex(model, fields, {}, cb);
});
}
}, function (err) {
setTimeout(function() {
client.close(function() {
callback(err);
});
}, timeout);
});
});
} else {
client.close(function() {
callback(err);
});
}
});
});
};
function createIndices() {
var properties = self._models[model].properties;
if (Object.keys(properties).length > 0) {
r.db(self.database).table(model).indexList().run(client, function(error, cursor) {
if (error) {
return cb2(error);
}
cursor.toArray(function(error, list) {
if (error) {
return cb2(error);
}
async.each(Object.keys(properties), function(property, cb3) {
if ((properties[property].index || self._foreignKeys[model].indexOf(property) >= 0) && list.indexOf(property) < 0) {
r.db(self.database).table(model).indexCreate(property).run(client, function(error) {
if (error)
return cb3(error);
cb3();
});
} else {
cb3();
}
}, function(err) {
cb2(err);
RethinkDB.prototype.ensureIndex = function (model, fields, params, callback) {
var self = this, indexes = [];
var properties = fields || self._models[model].properties;
if (Object.keys(properties).length > 0) {
r.connect({host: self.s.host, port: self.s.port}, function (err, client) {
if (err) {
return callback && callback(err);
}
Object.keys(properties).forEach(function (property) {
if ((properties[property].unique || properties[property].index || self._foreignKeys[model].indexOf(property) >= 0)) {
indexes.push(property);
}
});
var len = indexes.length;
if(len === 0) {
return callback && callback();
}
r.db(self.database).table(model).indexList().run(client, function (err, cursor) {
if (err || !cursor) {
return callback && callback(err);
}
cursor.toArray(function (err, list) {
if (err) {
return callback && callback(err);
}
indexes.forEach(function(index){
if(list.indexOf(index) === -1){
r.db(self.database).table(model).indexCreate(index).run(client, function (error) {
if (error) {
return callback && callback(error);
}
if (--len === 0) {
process.nextTick(function() {
client.close(function() {
return callback && callback();
});
});
}
});
} else {
if (--len === 0) {
process.nextTick(function() {
client.close(function() {
return callback && callback();
});
});
} else {
cb2();
}
}
}, function(err) {
self.pool.release(client);
cb(err);
});
});
} else {
self.pool.release(client);
cb(error);
}
});
});
});
} else {
return callback && callback();
}
};
// drops tables and re-creates them
RethinkDB.prototype.automigrate = function(cb) {
this.autoupdate(cb);
RethinkDB.prototype.automigrate = function (callback) {
this.autoupdate(callback);
};
// checks if database needs to be actualized
RethinkDB.prototype.isActual = function(cb) {
RethinkDB.prototype.isActual = function (callback) {
var self = this;
self.pool.acquire(function(error, client) {
if (error)
self.pool.acquire(function (error, client) {
if (error) {
throw error;
r.db(self.database).tableList().run(client, function(error, cursor) {
}
r.db(self.database).tableList().run(client, function (error, cursor) {
if (!error) {
if (cursor.hasNext()) {
cursor.toArray(function(error, list) {
cursor.toArray(function (error, list) {
if (error) {
self.pool.release(client);
return cb(error);
return callback(error);
}
var actual = true;
async.each(Object.keys(self._models), function(model, cb2) {
if (!actual)
return cb2();
async.each(Object.keys(self._models), function (model, cb) {
if (!actual) {
return cb();
}
var properties = self._models[model].properties;
if (list.indexOf(model) < 0) {
actual = false;
cb2();
cb();
} else {
r.db(self.database).table(model).indexList().run(client, function(error, cursor) {
if (error)
return cb2(error);
cursor.toArray(function(error, list) {
if (error)
return cb2(error);
Object.keys(properties).forEach(function(property) {
if ((properties[property].index || self._foreignKeys[model].indexOf(property) >= 0) && list.indexOf(property) < 0)
r.db(self.database).table(model).indexList().run(client, function (error, cursor) {
if (error) {
return cb(error);
}
cursor.toArray(function (error, list) {
if (error) {
return cb(error);
}
Object.keys(properties).forEach(function (property) {
if ((properties[property].index || self._foreignKeys[model].indexOf(property) >= 0) && list.indexOf(property) < 0) {
actual = false;
}
});
cb2();
cb();
});
});
}
}, function(err) {
}, function (err) {
self.pool.release(client);
cb(err, actual);
callback(err, actual);
});

@@ -233,7 +279,7 @@ });

self.pool.release(client);
cb(null, false);
callback(null, false);
}
} else {
self.pool.release(client);
cb(error);
callback(error);
}

@@ -244,3 +290,3 @@ });

RethinkDB.prototype.defineForeignKey = function(name, key, anotherName, cb) {
RethinkDB.prototype.defineForeignKey = function (name, key, anotherName, cb) {
this._foreignKeys[name].push(key);

@@ -250,6 +296,6 @@ cb(null, String);

RethinkDB.prototype.create = function(model, data, callback) {
RethinkDB.prototype.create = function (model, data, callback) {
var self = this;
self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error)

@@ -261,9 +307,11 @@ throw error;

}
Object.keys(data).forEach(function(key) {
if (data[key] instanceof Date)
Object.keys(data).forEach(function (key) {
if (data[key] instanceof Date) {
data[key] = moment(data[key]).unix();
if (data[key] === undefined)
}
if (data[key] === undefined) {
data[key] = null;
}
});
r.db(self.database).table(model).insert(data).run(client, function(err, m) {
r.db(self.database).table(model).insert(data).run(client, function (err, m) {
self.pool.release(client);

@@ -279,10 +327,10 @@ err = err || m.first_error && new Error(m.first_error);

RethinkDB.prototype.save = function(model, data, callback) {
RethinkDB.prototype.save = function (model, data, callback) {
var self = this;
self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error)
throw error;
Object.keys(data).forEach(function(key) {
Object.keys(data).forEach(function (key) {
if (data[key] instanceof Date)

@@ -293,3 +341,3 @@ data[key] = moment(data[key]).unix();

});
r.db(self.database).table(model).insert(data, {upsert: true}).run(client, function(err, notice) {
r.db(self.database).table(model).insert(data, {upsert: true}).run(client, function (err, notice) {
self.pool.release(client);

@@ -302,10 +350,9 @@ err = err || notice.first_error && new Error(notice.first_error);

RethinkDB.prototype.exists = function(model, id, callback) {
RethinkDB.prototype.exists = function (model, id, callback) {
var self = this;
self.pool.acquire(function(error, client) {
if (error)
self.pool.acquire(function (error, client) {
if (error) {
throw error;
r.db(self.database).table(model).get(id).run(client, function(err, data) {
}
r.db(self.database).table(model).get(id).run(client, function (err, data) {
self.pool.release(client);

@@ -319,14 +366,12 @@ callback(err, !!(!err && data));

var self = this;
self.pool.acquire(function(error, client) {
if (error)
self.pool.acquire(function (error, client) {
if (error) {
throw error;
r.db(self.database).table(model).get(id).run(client, function(err, data) {
}
r.db(self.database).table(model).get(id).run(client, function (err, data) {
if (data)
Object.keys(data).forEach(function(key) {
Object.keys(data).forEach(function (key) {
if (self._models[model].properties[key]['type']['name'] === "Date")
data[key] = moment.unix(data[key]).toDate();
}.bind(self));
self.pool.release(client);

@@ -340,3 +385,3 @@ callback(err, data);

var self = this;
self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error) {

@@ -348,3 +393,3 @@ throw error;

}
data.forEach(function(value, key) {
data.forEach(function (value, key) {
if (value instanceof Date) {

@@ -357,3 +402,3 @@ data[key] = moment(value).unix();

});
r.db(self.database).table(model).insert(data, {upsert: true}).run(client, function(err, m) {
r.db(self.database).table(model).insert(data, {upsert: true}).run(client, function (err, m) {
self.pool.release(client);

@@ -369,7 +414,7 @@ err = err || m.first_error && new Error(m.first_error);

self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error)
throw error;
r.db(self.database).table(model).get(id).delete().run(client, function(error, result) {
r.db(self.database).table(model).get(id).delete().run(client, function (error, result) {
self.pool.release(client);

@@ -384,3 +429,3 @@ callback(error);

self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error)

@@ -411,3 +456,3 @@ throw error;

promise.delete().run(client, function(error, cursor) {
promise.delete().run(client, function (error, cursor) {
self.pool.release(client);

@@ -422,3 +467,3 @@ callback(error);

self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error)

@@ -442,3 +487,3 @@ throw error;

}
keys.forEach(function(key) {
keys.forEach(function (key) {
var m = key.match(/\s+(A|DE)SC$/);

@@ -469,3 +514,3 @@ key = key.replace(/\s+(A|DE)SC$/, '').trim();

promise.run(client, function(error, cursor) {
promise.run(client, function (error, cursor) {
if (error) {

@@ -475,3 +520,3 @@ self.pool.release(client);

}
cursor.toArray(function(err, data) {
cursor.toArray(function (err, data) {
if (err) {

@@ -482,4 +527,4 @@ self.pool.release(client);

data.forEach(function(element, index) {
Object.keys(element).forEach(function(key) {
data.forEach(function (element, index) {
Object.keys(element).forEach(function (key) {
if (!_keys.hasOwnProperty(key))

@@ -508,6 +553,6 @@ return;

self.pool.acquire(function(error, client) {
self.pool.acquire(function (error, client) {
if (error)
throw error;
r.db(self.database).table(model).delete().run(client, function(error, result) {
r.db(self.database).table(model).delete().run(client, function (error, result) {
self.pool.release(client);

@@ -522,12 +567,12 @@ callback(error, result);

self.pool.acquire(function(error, client) {
if (error)
self.pool.acquire(function (error, client) {
if (error) {
throw error;
}
var promise = r.db(self.database).table(model);
if (where && typeof where === "object")
if (where && typeof where === "object") {
promise = _processWhere(self, model, where, promise);
promise.count().run(client, function(err, count) {
}
promise.count().run(client, function (err, count) {
self.pool.release(client);

@@ -542,23 +587,44 @@ callback(err, count);

self.pool.acquire(function(error, client) {
if (error)
self.pool.acquire(function (error, client) {
if (error) {
throw error;
}
data.id = id;
Object.keys(data).forEach(function(key) {
if (data[key] instanceof Date)
Object.keys(data).forEach(function (key) {
if (data[key] instanceof Date) {
data[key] = moment(data[key]).unix();
if (data[key] === undefined)
}
if (data[key] === undefined) {
data[key] = null;
}
});
r.db(self.database).table(model).update(data).run(client, function(err, object) {
self.pool.release(client);
cb(err, data);
});
r.db(self.database)
.table(model)
.update(data)
.run(client, function (err, object) {
self.pool.release(client);
cb(err, data);
});
});
};
RethinkDB.prototype.disconnect = function() {
RethinkDB.prototype.update = function (model, filter, data, cb) {
var self = this;
self.pool.drain(function() {
self.pool.acquire(function (error, client) {
if (error) {
throw error;
}
r.db(self.database).table(model)
.filter(filter)
.update(data)
.run(client, function (err, object) {
self.pool.release(client);
cb(err, data);
});
});
};
RethinkDB.prototype.disconnect = function () {
var self = this;
self.pool.drain(function () {
self.pool.destroyAllNow();

@@ -575,3 +641,3 @@ });

var queryExtra = [];
Object.keys(where).forEach(function(k) {
Object.keys(where).forEach(function (k) {
var spec, cond = where[k];

@@ -640,3 +706,3 @@ var allConds = [];

var query;
queryParts.forEach(function(comp) {
queryParts.forEach(function (comp) {
if (!query) {

@@ -651,3 +717,3 @@ query = comp;

}
queryExtra.forEach(function(comp) {
queryExtra.forEach(function (comp) {
promise = promise.filter(comp);

@@ -654,0 +720,0 @@ });

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

@@ -11,10 +11,9 @@ "name": "Aleksej Gordejev",

"homepage": "http://camintejs.com/",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/biggora/caminte/blob/master/LICENSE"
}
],
"license": "MIT",
"contributors": [
{
"name": "Aleksej Gordejev",
"email": "aleksej@gordejev.lv"
},
{
"name": "Anatoliy Chakkaev",

@@ -62,6 +61,2 @@ "email": "rpm1602@gmail.com"

"email": ""
},
{
"name": "Aleksej Gordejev",
"email": "aleksej@gordejev.lv"
}

@@ -71,2 +66,3 @@ ],

"orm",
"cross-db",
"caminte",

@@ -93,3 +89,3 @@ "database",

"support": "support",
"tests": "tests"
"test": "test"
},

@@ -102,3 +98,3 @@ "repository": {

"scripts": {
"test": "nodeunit tests/*_test*"
"test": "make test"
},

@@ -112,7 +108,13 @@ "engines": [

"devDependencies": {
"semicov": "*",
"coffee-script": "*",
"nodeunit": "*",
"semicov": "latest",
"underscore": "latest",
"generic-pool": "latest",
"moment": "latest",
"async": "latest",
"mocha": "latest",
"should": "latest",
"istanbul": "latest",
"jshint": "2.x",
"redis": ">= 0.12.0",
"hiredis": "*",
"mongoose": ">= 3.0.0",

@@ -128,3 +130,2 @@ "mysql": ">= 2.0.0",

"rethinkdb": ">= 1.16",
"generic-pool": "*",
"cassandra-driver": ">=2.1.0"

@@ -131,0 +132,0 @@ },

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

## Tests
```
# run all tests
$ make test
# run sqlite tests
$ make test-sqlite
# run mysql tests
$ make test-mysql
# run postgres tests
$ make test-postgres
# run redis tests
$ make test-redis
# run mongodb tests
$ make test-mongo
```
## Contributing

@@ -165,0 +187,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

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