Skip to content

Commit e6649f2

Browse files
committed
Merge pull request brianc#925 from mnahkies/fix-prepare-value-map-to-postgres
Fix prepare value map to postgres
2 parents 8807936 + 3a9f5c3 commit e6649f2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/utils.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ function normalizeQueryConfig (config, values, callback) {
103103
}
104104

105105
module.exports = {
106-
prepareValue: prepareValue,
106+
prepareValue: function prepareValueWrapper (value) {
107+
//this ensures that extra arguments do not get passed into prepareValue
108+
//by accident, eg: from calling values.map(utils.prepareValue)
109+
return prepareValue(value);
110+
},
107111
normalizeQueryConfig: normalizeQueryConfig
108112
};

test/unit/utils-tests.js

+11
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,14 @@ test('prepareValue: objects with circular toPostgres rejected', function() {
171171
}
172172
throw new Error("Expected prepareValue to throw exception");
173173
});
174+
175+
test('prepareValue: can safely be used to map an array of values including those with toPostgres functions', function() {
176+
var customType = {
177+
toPostgres: function() {
178+
return "zomgcustom!";
179+
}
180+
};
181+
var values = [1, "test", customType]
182+
var out = values.map(utils.prepareValue)
183+
assert.deepEqual(out, [1, "test", "zomgcustom!"])
184+
})

0 commit comments

Comments
 (0)