Do not store null values
This commit is contained in:
parent
c3835d089b
commit
a8db2ad081
|
@ -39,6 +39,7 @@ BridgeToRedis.prototype.defineForeignKey = function (model, key, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
BridgeToRedis.prototype.save = function (model, data, callback) {
|
BridgeToRedis.prototype.save = function (model, data, callback) {
|
||||||
|
deleteNulls(data);
|
||||||
var log = this.logger('HMSET ' + model + ':' + data.id + ' ...');
|
var log = this.logger('HMSET ' + model + ':' + data.id + ' ...');
|
||||||
this.client.hmset(model + ':' + data.id, data, function (err) {
|
this.client.hmset(model + ':' + data.id, data, function (err) {
|
||||||
log();
|
log();
|
||||||
|
@ -214,12 +215,19 @@ BridgeToRedis.prototype.count = function count(model, callback) {
|
||||||
|
|
||||||
BridgeToRedis.prototype.updateAttributes = function updateAttrs(model, id, data, cb) {
|
BridgeToRedis.prototype.updateAttributes = function updateAttrs(model, id, data, cb) {
|
||||||
var t1 = Date.now();
|
var t1 = Date.now();
|
||||||
|
deleteNulls(data);
|
||||||
this.client.hmset(model + ':' + id, data, function () {
|
this.client.hmset(model + ':' + id, data, function () {
|
||||||
this.log('HMSET ' + model + ':' + id, t1);
|
this.log('HMSET ' + model + ':' + id, t1);
|
||||||
this.updateIndexes(model, id, data, cb);
|
this.updateIndexes(model, id, data, cb);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function deleteNulls(data) {
|
||||||
|
Object.keys(data).forEach(function (key) {
|
||||||
|
if (data[key] === null) delete data[key];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
BridgeToRedis.prototype.disconnect = function disconnect() {
|
BridgeToRedis.prototype.disconnect = function disconnect() {
|
||||||
this.log('QUIT', Date.now());
|
this.log('QUIT', Date.now());
|
||||||
this.client.quit();
|
this.client.quit();
|
||||||
|
|
|
@ -309,7 +309,7 @@ function testOrm(schema) {
|
||||||
res.forEach(function (r) {
|
res.forEach(function (r) {
|
||||||
if (r.title != 'New title') pass = false;
|
if (r.title != 'New title') pass = false;
|
||||||
});
|
});
|
||||||
test.ok(res.length > 0);
|
test.ok(res.length > 0, 'Exact match with string returns dataset');
|
||||||
test.ok(pass, 'Exact match with string');
|
test.ok(pass, 'Exact match with string');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -321,7 +321,7 @@ function testOrm(schema) {
|
||||||
res.forEach(function (r) {
|
res.forEach(function (r) {
|
||||||
if (r.title != null) pass = false;
|
if (r.title != null) pass = false;
|
||||||
});
|
});
|
||||||
test.ok(res.length > 0);
|
test.ok(res.length > 0, 'Matching null returns dataset');
|
||||||
test.ok(pass, 'Matching null');
|
test.ok(pass, 'Matching null');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -332,7 +332,7 @@ function testOrm(schema) {
|
||||||
res.forEach(function (r) {
|
res.forEach(function (r) {
|
||||||
if (!r.title || !r.title.match(/hello/i)) pass = false;
|
if (!r.title || !r.title.match(/hello/i)) pass = false;
|
||||||
});
|
});
|
||||||
test.ok(res.length > 0);
|
test.ok(res.length > 0, 'Matching regexp returns dataset');
|
||||||
test.ok(pass, 'Matching regexp');
|
test.ok(pass, 'Matching regexp');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,13 +2,14 @@ juggling = require('../index')
|
||||||
Schema = juggling.Schema
|
Schema = juggling.Schema
|
||||||
Text = Schema.Text
|
Text = Schema.Text
|
||||||
|
|
||||||
DBNAME = 'migrationtest'
|
DBNAME = process.env.DBNAME || 'migrationtest'
|
||||||
DBUSER = 'root'
|
DBUSER = process.env.DBUSER || 'root'
|
||||||
DBPASS = ''
|
DBPASS = ''
|
||||||
|
DBENGINE = process.env.DBENGINE || 'mysql'
|
||||||
|
|
||||||
require('./spec_helper').init module.exports
|
require('./spec_helper').init module.exports
|
||||||
|
|
||||||
schema = new Schema 'mysql', database: '', username: DBUSER, password: DBPASS
|
schema = new Schema DBENGINE, database: '', username: DBUSER, password: DBPASS
|
||||||
schema.log = (q) -> console.log q
|
schema.log = (q) -> console.log q
|
||||||
|
|
||||||
query = (sql, cb) ->
|
query = (sql, cb) ->
|
||||||
|
|
Loading…
Reference in New Issue