不要怂,就是干,撸起袖子干!

You need to sign in or sign up before continuing.
Commit 0cee002a by Geoffrey Plitt Committed by Jan Aagaard Meier

fix allowing assigning JSON fields back to NULL

adding a test. not able to run locally so will check Travis result

attempting test fix

fixing another bug

fixing accidentally removed code from before

fixing missing semicolon

fixed parentheses mistake

reverting lib/utils.js back to the way it was

upgrading version of lodash

adding simpler test of escape function with NULL for json field

getting rid of old test

fixing newline

fixing cloneDeep()
1 parent 30145e0f
......@@ -890,7 +890,7 @@ var QueryGenerator = {
else if (DataTypes.ARRAY.is(field.type, DataTypes.RANGE)) { // escape array of ranges
return 'ARRAY[' + Utils._.map(value, function(v){return "'" + range.stringify(v) + "'";}).join(',') + ']::' + field.type.toString();
}
} else if (field && field.type instanceof DataTypes.JSON) {
} else if (value!==null && field && field.type instanceof DataTypes.JSON) {
value = JSON.stringify(value);
} else if (Array.isArray(value) && field && DataTypes.ARRAY.is(field.type, DataTypes.JSON)) {
var jsonType = field.type.type; // type may be JSON or JSONB
......
......@@ -96,7 +96,7 @@ var Utils = module.exports = {
cloneDeep: function(obj, fn) {
return lodash.cloneDeep(obj, function (elem) {
// Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
if (!!Utils._.get(elem, 'clone') && typeof elem.clone === 'function') {return elem.clone(); }
if (elem && typeof elem.clone === 'function') {return elem.clone(); }
// Unfortunately, lodash.cloneDeep doesn't preserve Buffer.isBuffer, which we have to rely on for binary data
if (Buffer.isBuffer(elem)) { return elem; }
......
......@@ -37,7 +37,7 @@
"dottie": "^0.3.1",
"generic-pool": "2.2.0",
"inflection": "^1.6.0",
"lodash": "^3.5.0",
"lodash": "^3.9.3",
"moment": "^2.9.0",
"moment-timezone": "^0.3.1",
"node-uuid": "~1.4.1",
......
......@@ -25,6 +25,12 @@ if (current.dialect.supports.JSON) {
});
});
test('NULL', function () {
expectsql(sql.escape(null, { type: new DataTypes.JSON() }), {
default: 'NULL'
});
});
test('nested object', function () {
expectsql(sql.escape({ some: 'nested', more: { nested: true }, answer: 42 }, { type: new DataTypes.JSON() }), {
default: '\'{"some":"nested","more":{"nested":true},"answer":42}\''
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!