pass prepareValue
hook to toPostgres
Pass `toPostgres` type-coercers a reference to the `prepareValue` function to ease constructing literals composed of other Postgres types.
This commit is contained in:
parent
6ced524390
commit
619ba46ffe
@ -68,7 +68,7 @@ function prepareObject(val, seen) {
|
|||||||
}
|
}
|
||||||
seen.push(val);
|
seen.push(val);
|
||||||
|
|
||||||
return prepareValue(val.toPostgres(), seen);
|
return prepareValue(val.toPostgres(prepareValue), seen);
|
||||||
}
|
}
|
||||||
return JSON.stringify(val);
|
return JSON.stringify(val);
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,18 @@ test('prepareValue: objects with complex toPostgres prepared properly', function
|
|||||||
assert.strictEqual(out, '{"1","2"}');
|
assert.strictEqual(out, '{"1","2"}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('prepareValue: objects with toPostgres receive prepareValue', function() {
|
||||||
|
var customRange = {
|
||||||
|
lower: { toPostgres: function() { return 5; } },
|
||||||
|
upper: { toPostgres: function() { return 10; } },
|
||||||
|
toPostgres: function(prepare) {
|
||||||
|
return "[" + prepare(this.lower) + "," + prepare(this.upper) + "]";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var out = utils.prepareValue(customRange);
|
||||||
|
assert.strictEqual(out, "[5,10]");
|
||||||
|
});
|
||||||
|
|
||||||
test('prepareValue: objects with circular toPostgres rejected', function() {
|
test('prepareValue: objects with circular toPostgres rejected', function() {
|
||||||
var buf = new Buffer("zomgcustom!");
|
var buf = new Buffer("zomgcustom!");
|
||||||
var customType = {
|
var customType = {
|
||||||
|
Loading…
Reference in New Issue
Block a user