Skip to content

Fix prepare value map to postgres #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ function normalizeQueryConfig (config, values, callback) {
}

module.exports = {
prepareValue: prepareValue,
prepareValue: function prepareValueWrapper (value) {
//this ensures that extra arguments do not get passed into prepareValue
//by accident, eg: from calling values.map(utils.prepareValue)
return prepareValue(value);
},
normalizeQueryConfig: normalizeQueryConfig
};
11 changes: 11 additions & 0 deletions test/unit/utils-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,14 @@ test('prepareValue: objects with circular toPostgres rejected', function() {
}
throw new Error("Expected prepareValue to throw exception");
});

test('prepareValue: can safely be used to map an array of values including those with toPostgres functions', function() {
var customType = {
toPostgres: function() {
return "zomgcustom!";
}
};
var values = [1, "test", customType]
var out = values.map(utils.prepareValue)
assert.deepEqual(out, [1, "test", "zomgcustom!"])
})