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.3 to 0.1.4

5

lib/abstract-class.js

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

function mergeParams(base, update) {
if(update && !update.where) {
update = {
where : update
};
}
if (update.where) {

@@ -1418,0 +1423,0 @@ base.where = helpers.merge(base.where, update.where);

7

lib/adapters/mysql.js

@@ -243,7 +243,8 @@ /**

var UNIQ = 'undefined' !== typeof m.properties[prop]['unique'] ? ' UNIQUE ' : '';
sql.push('ALTER TABLE ' + self.tableEscaped(model) + ' ADD ' + UNIQ + ' INDEX `' + prop + '` (`' + prop + '`)');
sql.push(' ADD ' + UNIQ + ' INDEX `' + prop + '` (`' + prop + '`)');
}
}
if (sql.length) {
self.command(sql.join(';\n'), done);
self.command('ALTER TABLE ' + self.tableEscaped(model) + sql.join(',\n') + ';', done);
} else {

@@ -672,3 +673,3 @@ done();

if (sql.length) {
var query = 'ALTER TABLE ' + self.tableEscaped(model) + ' ' + sql.join(',\n');
var query = 'ALTER TABLE ' + self.tableEscaped(model) + ' \n' + sql.join(',\n');
if (checkOnly) {

@@ -675,0 +676,0 @@ done(null, true, {

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

var clientWrapper = new Client(schema.client);
schema.adapter = new BridgeToRedis(clientWrapper);
schema.adapter = new BridgeToRedis(schema.settings, clientWrapper);
clientWrapper._adapter = schema.adapter;

@@ -170,3 +170,3 @@ };

function BridgeToRedis(client) {
function BridgeToRedis(s, client) {
this.name = 'redis';

@@ -176,2 +176,3 @@ this._models = {};

this.indexes = {};
this.settings = s;
}

@@ -203,10 +204,21 @@

for (var i in data) {
if (!p[i])
if (!p[i]) {
continue;
if (!data[i]) {
data[i] = "";
continue;
}
switch (p[i].type.name) {
case "Date":
if (typeof data[i] === 'undefined' || data[i] === null) {
if(p[i].default || p[i].default === 0) {
if(typeof p[i].default === 'function') {
data[i] = p[i].default();
} else {
data[i] = p[i].default;
}
} else {
data[i] = "";
continue;
}
}
switch ((p[i].type.name || '').toString().toLowerCase()) {
case "date":
if (data[i].getTime) {

@@ -220,10 +232,10 @@ data[i] = data[i].getTime().toString();

break;
case "Number":
case "number":
data[i] = data[i].toString();
break;
case "Boolean":
case "boolean":
data[i] = !!data[i] ? "1" : "0";
break;
case "String":
case "Text":
case "string":
case "text":
break;

@@ -233,2 +245,3 @@ default:

}
}

@@ -241,11 +254,21 @@ return data;

for (var i in data) {
if (!p[i])
if (!p[i]) {
continue;
if (!data[i]) {
data[i] = "";
continue;
}
switch (p[i].type.name) {
case "Date":
if (typeof data[i] === 'undefined' || data[i] === null) {
if(p[i].default || p[i].default === 0) {
if(typeof p[i].default === 'function') {
data[i] = p[i].default();
} else {
data[i] = p[i].default;
}
} else {
data[i] = "";
continue;
}
}
switch ((p[i].type.name || '').toString().toLowerCase()) {
case "date":
d = new Date(data[i]);

@@ -255,6 +278,6 @@ d.setTime(data[i]);

break;
case "Number":
case "number":
data[i] = Number(data[i]);
break;
case "Boolean":
case "boolean":
data[i] = data[i] === "1";

@@ -286,6 +309,6 @@ break;

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

@@ -339,5 +362,5 @@ Object.keys(prevData).forEach(function (k) {

BridgeToRedis.prototype.create = function (model, data, callback) {
if (data.id)
if (data.id) {
return create.call(this, data.id, true);
}
this.client.incr('id:' + model, function (err, id) {

@@ -534,2 +557,3 @@ create.call(this, id);

}
var self = this;

@@ -609,3 +633,3 @@ var dest = 'temp:' + (Date.now() * Math.random());

if (filter.limit) {
var offset = (filter.offset || 0), limit = filter.limit;
var offset = (filter.offset || filter.skip || 0), limit = filter.limit;
sortCmd.push("LIMIT", offset, limit);

@@ -641,2 +665,3 @@ }

}
if (indexes && indexes.length > 0) {

@@ -652,2 +677,5 @@ indexes.forEach(function (idx) {

function handleKeys(err, keys) {
if(err) {
console.log(err);
}
var query = keys.map(function (key) {

@@ -663,4 +691,2 @@ return ['hgetall', key];

return;
function numerically(a, b) {

@@ -673,2 +699,4 @@ return a[this[0]] - b[this[0]];

}
return;
});

@@ -675,0 +703,0 @@ };

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

@@ -6,0 +6,0 @@ "name": "Aleksej Gordejev",

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

$ make test-mongo
# run rethinkdb tests
$ make test-rethinkdb
```

@@ -185,0 +188,0 @@

@@ -32,3 +32,3 @@ /**

modify_ts: {type: schema.Date},
create_id: {type: schema.Number, limit: 21},
create_id: {type: schema.Number, limit: 21, index: true},
modify_id: {type: schema.Number, limit: 21},

@@ -38,2 +38,3 @@ meta_keys: {type: schema.String, limit: 155},

}, {});
/* Validators */

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

/**
* Created by Alex on 12/18/2015.
*/
/*
User.hasMany(Post, {as: 'posts', foreignKey: 'userId'});
// creates instance methods:
// user.posts(conds)
// user.posts.build(data) // like new Post({userId: user.id});
// user.posts.create(data) // build and save
Post.belongsTo(User, {as: 'author', foreignKey: 'userId'});
// creates instance methods:
// post.author(callback) -- getter when called with function
// post.author() -- sync getter when called without params
// post.author(user) -- setter when called with object
*/
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'test';
}
var driver = process.env.CAMINTE_DRIVER || 'sqlite';
var should = require('should');
var caminte = require('../../');
var config = require('./../lib/database');
var dbConf = config[driver];
var UserModel = require('./../lib/User');
var ArticleModel = require('./../lib/Article');
var Schema = caminte.Schema;
dbConf.host = process.env.DB_HOST || dbConf.host || '';
var schema = new Schema(dbConf.driver, dbConf);
var User = UserModel(schema);
var Article = ArticleModel(schema);
/**
* Simple tests for the User and Article model
*/
describe(driver + ' - relation:', function () {
'use strict';
var article, user, newUser = {
language: 'en',
first_name: 'Alex',
last_name: 'Gordan',
screen_name: 'alex',
email: 'rubles@example.com',
password: 'AAAAAAAAA',
age: 45
}, newArticle = {
language: 'en',
category_id: 1,
title: 'My Article',
alias: 'my-article',
mainpage: 0,
params: {
title: 1,
categories: 1
}
};
User.hasMany(Article, {as: 'articles', foreignKey: 'create_id'});
Article.belongsTo(User, {as: 'author', foreignKey: 'create_id'});
before(function (done) {
schema.autoupdate(function () {
user = new User(newUser);
user.save(function () {
done();
});
});
});
after(function (done) {
User.destroyAll(function () {
Article.destroyAll(done);
});
});
describe('#hasMany', function () {
it('#build', function (done) {
article = user.articles.build(newArticle);
should.exist(article);
article.alias.should.be.equal(newArticle.alias);
article.title.should.be.exactly(newArticle.title);
should.deepEqual(article.create_id.toString(), user.id.toString());
done();
});
it('#create', function (done) {
user.articles.create(newArticle, function (err, created) {
should.not.exist(err);
should.exist(created);
created.alias.should.be.equal(newArticle.alias);
created.title.should.be.exactly(newArticle.title);
should.deepEqual(created.create_id.toString(), user.id.toString());
done();
});
});
it('#get (articles)', function (done) {
user.articles(function (err, founds) {
should.not.exist(err);
founds.should.length(1);
should.deepEqual(founds[0].create_id.toString(), user.id.toString());
done();
});
});
});
describe('#belongsTo', function () {
it('#get (author)', function (done) {
article.author(function(err, found){
should.not.exist(err);
should.exist(found);
found.first_name.should.be.equal(newUser.first_name);
found.last_name.should.be.exactly(newUser.last_name);
should.deepEqual(article.create_id.toString(), found.id.toString());
done();
});
});
});
/*
User.hasMany(Post, {as: 'posts', foreignKey: 'userId'});
// creates instance methods:
// user.posts(conds)
// user.posts.build(data) // like new Post({userId: user.id});
// user.posts.create(data) // build and save
Post.belongsTo(User, {as: 'author', foreignKey: 'userId'});
// creates instance methods:
// post.author(callback) -- getter when called with function
// post.author() -- sync getter when called without params
// post.author(user) -- setter when called with object
*/
});

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

var category, newCategory = {
active: 0,
category_id: 2,

@@ -47,29 +48,34 @@ title: 'My Category',

it('#published', function (done) {
// Category.should.be.have.property('published');
// Category.scope.should.be.type('function');
/*
Category.published(function(err, founds){
Category.should.be.have.property('published');
Category.scope.should.be.type('function');
Category.published({}, function (err, founds) {
should.not.exist(err);
founds.should.length(1);
founds.should.length(0);
done();
});
*/
done();
});
it('#hidden', function (done) {
// Category.should.be.have.property('published');
// Category.scope.should.be.type('function');
/*
Category.hidden(function(err, founds){
Category.should.be.have.property('published');
Category.scope.should.be.type('function');
Category.hidden({}, function (err, founds) {
should.not.exist(err);
founds.should.length(1);
done();
});
});
it('#products', function (done) {
Category.should.be.have.property('products');
Category.scope.should.be.type('function');
Category.products({}, function (err, founds) {
should.not.exist(err);
founds.should.length(0);
done();
});
*/
done();
});
});
});

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc