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.1.6 to 0.2.0

test/schema/types.js

34

lib/adapters/mongodb.js

@@ -188,6 +188,7 @@ /**

MongoDB.prototype.findById = function findById(model, id, callback) {
id = getObjectId(id);
this.collection(model).findOne({_id: id}, function (err, data) {
var self = this; id = getObjectId(id);
self.collection(model).findOne({_id: id}, function (err, data) {
if (data) {
data.id = id;
data = self.fromDatabase(model, data);
}

@@ -242,3 +243,3 @@ callback(err, data);

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

@@ -270,7 +271,7 @@ if (filter.order) {

cursor.toArray(function (err, data) {
if (err)
if (err) {
return callback(err);
}
callback(null, data.map(function (o) {
o.id = o._id;
return o;
return self.fromDatabase(model, o);
}));

@@ -299,2 +300,23 @@ });

MongoDB.prototype.fromDatabase = function (model, data) {
var props = this._models[model].properties;
var clean = {};
Object.keys(data).forEach(function(key){
if (!props[key]) {
return;
}
if(props[key].type.name.toString().toLowerCase() === 'date') {
if(data[key]) {
clean[key] = new Date(data[key]);
} else {
clean[key] = data[key];
}
} else {
clean[key] = data[key];
}
});
clean.id = data._id;
return clean;
};
MongoDB.prototype.disconnect = function () {

@@ -301,0 +323,0 @@ this.client.close();

31

lib/adapters/neo4j.js

@@ -218,4 +218,6 @@ /**

Object.keys(data).forEach(function (key) {
if (!props[key]) return;
cdata[key] = self.toDatabase(props[key], data[key]);
});
self.client.insertNode(cdata, model, function (err, node) {

@@ -391,7 +393,7 @@ if (err) {

}
if (prop.type.name === 'Number') {
var type = (prop.type.name || '').toString().toLowerCase();
if (type === 'number') {
return val;
}
if (prop.type.name === 'Date') {
if (type === 'date') {
if (!val) {

@@ -408,5 +410,10 @@ return 0;

}
if (prop.type.name === "Boolean") {
if (type === "boolean") {
return val ? 1 : 0;
}
if (type === "json") {
if (typeof val === 'object') {
val = JSON.stringify(val);
}
}
return esc ? '\'' + val.toString() + '\'' : val.toString();

@@ -426,4 +433,5 @@ };

}
var type = (props[key].type.name || '').toString().toLowerCase();
if (props[key].type.name === 'Date' && val !== null) {
if (type === 'date' && val !== null) {
if (val !== '') {

@@ -434,2 +442,11 @@ clean[key] = new Date(val);

}
} else if (type === 'json') {
if (typeof val === 'string') {
try {
clean[key] = JSON.parse(val);
} catch(err){}
} else {
clean[key] = val;
}
} else {

@@ -507,7 +524,7 @@ clean[key] = val;

case 'nin':
sqlCond = ' NOT ( '+keyEscaped+' IN ['+val+'])';
sqlCond = ' NOT ( ' + keyEscaped + ' IN [' + val + '])';
break;
case 'neq':
case 'ne':
sqlCond = ' NOT ( '+keyEscaped+' = '+val+' )';
sqlCond = ' NOT ( ' + keyEscaped + ' = ' + val + ' )';
break;

@@ -514,0 +531,0 @@ case 'regex':

@@ -36,2 +36,4 @@ /**

database: s.database || process.env.USER,
poolIdleTimeout: s.poolIdleTimeout || 15000,
poolSize: s.poolSize || s.pool || 25,
debug: s.debug

@@ -57,3 +59,3 @@ });

if (!err) {
callback();
return callback && callback();
} else {

@@ -68,3 +70,3 @@ throw err;

var s = schema.settings;
pg.connect({
return pg.connect({
host: s.host || 'localhost',

@@ -80,3 +82,3 @@ port: s.port || 5432,

}
client.query('CREATE DATABASE ' + s.database + ' OWNER ' + s.username + ' ENCODING \'UTF8\'', function (err) {
return client.query('CREATE DATABASE ' + s.database + ' OWNER ' + s.username + ' ENCODING \'UTF8\'', function (err) {
if (err) {

@@ -86,3 +88,4 @@ // console.log(err, 'ignoring the error');

client.end();
callback();
done();
return callback && callback();
});

@@ -96,8 +99,11 @@ });

PG.prototype.query = function (sql, callback) {
var self = this,time = Date.now();
var log = self.log;
self.client.query(sql, function (err, data) {
PG.prototype.query = function (sql, vals, callback) {
var self = this, time = Date.now(), log = self.log;
if (typeof vals === 'function') {
callback = vals;
vals = {};
}
self.client.query(sql, vals, function (err, data) {
if (log) {
log(sql, time);
log(time, sql);
}

@@ -123,2 +129,3 @@ callback(err, data ? data.rows : null);

sql += ' RETURNING id';
this.query(sql, function (err, info) {

@@ -129,3 +136,3 @@ if (err) {

callback(err, info && info[0] && info[0].id);
});
}.bind(this));
};

@@ -238,4 +245,5 @@

if (props[key]) {
if (key === 'id')
if (key === 'id') {
return;
}
columns.push('"' + key + '"');

@@ -249,4 +257,5 @@ fields.push(this.toDatabase(props[key], data[key]));

if (props[key]) {
if (key === 'id')
if (key === 'id') {
return;
}
fields.push('"' + key + '" = ' + this.toDatabase(props[key], data[key]));

@@ -286,16 +295,4 @@ }

}
if (val.constructor.name === 'Object') {
var operator = Object.keys(val)[0];
val = val[operator];
if (operator === 'between') {
return this.toDatabase(prop, val[0]) + ' AND ' + this.toDatabase(prop, val[1]);
}
if (operator === 'inq' || operator === 'nin') {
for (var i = 0; i < val.length; i++) {
val[i] = escape(val[i]);
}
return val.join(',');
}
}
if (prop.type.name === 'Number') {
var type = (prop.type.name || '').toString().toLowerCase();
if (type === 'number') {
if (!val && val !== 0) {

@@ -312,3 +309,3 @@ if (prop.autoIncrement) {

if (prop.type.name === 'Date') {
if (type === 'date') {
if (!val) {

@@ -327,2 +324,7 @@ if (prop.autoIncrement) {

}
if (type === 'json') {
return '\'' + JSON.stringify(val) + '\'';
}
return escape(val.toString());

@@ -341,7 +343,3 @@

if (props[key]) {
if ((props[key].type.name || '').toString().toLowerCase() === 'json' && typeof val == "string") {
data[key] = JSON.parse(val);
} else {
data[key] = val;
}
data[key] = val;
}

@@ -386,20 +384,14 @@ });

function getTableStatus(cls, model, callback) {
function decoratedCallback(err, data) {
data.forEach(function (field) {
field.Type = mapPostgresDatatypes(field.Type);
});
return callback && callback(err, data);
}
cls.query('SELECT column_name as "Field", udt_name as "Type", is_nullable as "Null", column_default as "Default" FROM information_schema.COLUMNS WHERE table_name = \'' + cls.table(model) + '\'', decoratedCallback);
}
PG.prototype.autoupdate = function (callback) {
var self = this;
var wait = 0;
Object.keys(this._models).forEach(function (model) {
Object.keys(self._models).forEach(function (model) {
wait += 1;
var indexes = [];
getTableStatus(self, model, function (err, fields) {
var sql = 'SELECT column_name as "Field", udt_name as "Type", is_nullable as "Null", column_default as "Default" FROM information_schema.COLUMNS WHERE table_name = \'' + self.table(model) + '\';';
self.client.query(sql, function (err, fields) {
if (!err && fields.length) {
fields.forEach(function (field) {
field.Type = mapPostgresDatatypes(field.Type);
});
self.alterTable(model, fields, indexes, done);

@@ -409,4 +401,5 @@ } else {

}
});
});
}.bind(self));

@@ -413,0 +406,0 @@ function done(err) {

@@ -198,3 +198,3 @@ /**

BridgeToRedis.prototype.forDb = function (model, data) {
BridgeToRedis.prototype.forDatabase = function (model, data) {
var p = this._models[model].properties;

@@ -205,3 +205,2 @@ for (var i in data) {

}
if (typeof data[i] === 'undefined' || data[i] === null) {

@@ -236,7 +235,9 @@ if(p[i].default || p[i].default === 0) {

break;
case "string":
case "text":
case "json":
if(typeof data[i] === 'object') {
data[i] = JSON.stringify(data[i]);
}
break;
default:
data[i] = JSON.stringify(data[i]);
data[i] = data[i].toString();
}

@@ -248,3 +249,3 @@

BridgeToRedis.prototype.fromDb = function (model, data) {
BridgeToRedis.prototype.fromDatabase = function (model, data) {
var p = this._models[model].properties, d;

@@ -255,3 +256,3 @@ for (var i in data) {

}
var type = (p[i].type.name || '').toString().toLowerCase();
if (typeof data[i] === 'undefined' || data[i] === null) {

@@ -270,3 +271,11 @@ if(p[i].default || p[i].default === 0) {

switch ((p[i].type.name || '').toString().toLowerCase()) {
switch (type) {
case "json":
try {
if(typeof data[i] === 'string') {
data[i] = JSON.parse(data[i]);
}
} catch(err) {
}
break;
case "date":

@@ -283,13 +292,3 @@ d = new Date(data[i]);

break;
default:
d = data[i];
try {
data[i] = JSON.parse(data[i]);
if (typeof data[i] !== 'object') {
data[i] = d;
}
}
catch (e) {
data[i] = d;
}
}

@@ -302,3 +301,3 @@ }

var self = this;
data = self.forDb(model, data);
data = self.forDatabase(model, data);
deleteNulls(data);

@@ -309,3 +308,3 @@ self.client.hgetall(model + ':' + data.id, function (err, prevData) {

}
self.client.hmset([model + ':' + data.id, self.forDb(model, data)], function (err) {
self.client.hmset([model + ':' + data.id, self.forDatabase(model, data)], function (err) {
if (err) {

@@ -322,3 +321,3 @@ return callback(err);

}
self.updateIndexes(model, data.id, data, callback, self.forDb(model, prevData));
self.updateIndexes(model, data.id, data, callback, self.forDatabase(model, prevData));
}.bind(this));

@@ -427,3 +426,3 @@ }.bind(this));

}
data = self.fromDb(model, data);
data = self.fromDatabase(model, data);
callback(err, data);

@@ -683,3 +682,3 @@ }.bind(this));

callback(err, (replies || []).map(function (r) {
return self.fromDb(model, r);
return self.fromDatabase(model, r);
}));

@@ -819,2 +818,2 @@ }.bind(this));

this.client.quit();
};
};

@@ -241,6 +241,19 @@ /**

Object.keys(data).forEach(function (key) {
var val = data[key];
var val = data[key], type = (props[key].type.name || '').toString().toLowerCase();
if (props[key]) {
if ((props[key].type.name || '').toString().toLowerCase() === 'json' && typeof val == "string") {
if (type === 'json' && typeof val == "string") {
data[key] = JSON.parse(val);
} else if (type === 'date') {
if (!val) {
val = null;
}
if (typeof val === 'string') {
val = val.split('.')[0].replace('T', ' ');
val = Date.parse(val);
}
if (typeof val === 'number') {
val = new Date(val);
}
data[key] = val;
} else {

@@ -247,0 +260,0 @@ data[key] = val;

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

@@ -100,30 +100,31 @@ "name": "Aleksej Gordejev",

"dependencies": {
"node-uuid": ">= 1.3.3"
"node-uuid": ">= 1.3.3",
"sqlite3": "^3.1.1"
},
"devDependencies": {
"arangojs": ">= 4.2.0",
"async": "latest",
"cassandra-driver": ">=2.1.0",
"coffee-script": "*",
"semicov": "latest",
"underscore": "latest",
"cradle": ">= 0.6.0",
"felix-couchdb": ">= 1.0.0",
"generic-pool": "latest",
"moment": "latest",
"async": "latest",
"mocha": "latest",
"should": "latest",
"istanbul": "latest",
"jshint": "2.x",
"redis": ">= 0.12.0",
"mocha": "latest",
"moment": "latest",
"mongodb": ">= 2.0.0",
"mongoose": ">= 3.0.0",
"mysql": ">= 2.0.0",
"node-neo4j": "^2.0.3",
"pg": ">= 4.0.0",
"sqlite3": ">= 3.0.0",
"redis": ">= 0.12.0",
"rethinkdb": ">= 1.16",
"riak-js": ">= 1.0.0",
"node-neo4j": "^2.0.3",
"mongodb": ">= 2.0.0",
"felix-couchdb": ">= 1.0.0",
"cradle": ">= 0.6.0",
"rethinkdb": ">= 1.16",
"cassandra-driver": ">=2.1.0",
"arangojs": ">= 4.2.0"
"semicov": "latest",
"should": "latest",
"sqlite3": "^3.1.1",
"underscore": "latest"
},
"optionalDependencies": {}
}

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

mainpage: {type: schema.Number, limit: 1, index: true},
featured: {type: schema.Boolean, default: true, index: true},
language: {type: schema.String, limit: 5, default: "en", index: true},

@@ -30,10 +31,14 @@ category_id: {type: schema.Number, limit: 11, default: 0, index: true},

template: {type: schema.String, limit: 255, default: "default"},
params: {type: schema.Text},
create_ts: {type: schema.Date},
params: {type: schema.Json},
longitude: {type: schema.Double},
latitude: {type: schema.Real},
price: {type: schema.Float},
create_ts: {type: schema.Date, default: Date.now},
modify_ts: {type: schema.Date},
create_id: {type: schema.Number, limit: 21, index: true},
modify_id: {type: schema.Number, limit: 21, index: true},
meta_keys: {type: schema.String, limit: 155},
meta_keys: {type: schema.Json},
meta_desc: {type: schema.String, limit: 155}
}, {});
/* Validators */

@@ -40,0 +45,0 @@ Article.validatesPresenceOf('title', 'alias');

@@ -72,3 +72,9 @@ /**

categories: 1
}
},
content_short: 'Application developer focusing on web, mobile and server platforms. Always aiming to use software engineering’s best practices, like testability and design patterns, in a system’s implementation to achieve flexibility and scalability.',
content_full: 'Application developer focusing on web, mobile and server platforms. Always aiming to use software engineering’s best practices, like testability and design patterns, in a system’s implementation to achieve flexibility and scalability.',
meta_keys: ['app', 'developer', 'web'],
longitude: 56.9496490,
latitude: 24.1051860,
price: 23.56
},

@@ -75,0 +81,0 @@ {

@@ -58,3 +58,3 @@ /**

should.not.exist(err);
found.id.should.equal(id);
found.id.should.deepEqual(id);
done();

@@ -61,0 +61,0 @@ });

@@ -57,3 +57,3 @@ /**

should.not.exist(err);
found.id.should.equal(id);
found.id.should.deepEqual(id);
done();

@@ -60,0 +60,0 @@ });

@@ -54,3 +54,3 @@ /**

should.not.exist(err);
found.id.should.equal(id);
found.id.should.deepEqual(id);
done();

@@ -57,0 +57,0 @@ });

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

var config = require('./../lib/database');
var samples = require('./../lib/data');
var dbConf = config[driver];

@@ -20,13 +21,5 @@ var UserModel = require('./../lib/User');

describe(driver + ' - hooks:', function () {
describe(driver + ' - schema hooks:', function () {
'use strict';
var user, nuser, newUser = {
language: 'en',
first_name: 'Alex',
last_name: 'Gordan',
screen_name: 'alex',
email: 'bubles@example.com',
password: 'AAAAAAAAA',
age: 45
};
var user, nuser, newUser = samples.users[0];

@@ -37,2 +30,6 @@ before(function (done) {

after(function (done) {
User.destroyAll(done);
});
it("#afterInitialize", function (done) {

@@ -39,0 +36,0 @@ User.afterInitialize = function () {

@@ -25,3 +25,3 @@ /**

*/
describe(driver + ' - scope:', function () {
describe(driver + ' - schema scope:', function () {
'use strict';

@@ -28,0 +28,0 @@ var category, newCategory = samples.categories[0];

@@ -25,3 +25,3 @@ /**

*/
describe(driver + ' - validation:', function () {
describe(driver + ' - schema validation:', function () {
'use strict';

@@ -28,0 +28,0 @@ var user1, user2,

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