package
camel-casing for postgres result field names
npm install pg-camelcaseGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 19 packages.
538.7 kB
Includes dependencies.
pg-camelcaseChanges the fieldnames of a query result from snake_case_nameing to camelCaseNaming. The module exposes two functions:
#inject(pg): changes the internals of pg to change the result as
desribed. Also, it returns a function which can be called to revert
this change#camelCase(str): returns the string str converted to camel caseExample:
var pg = require('pg');
var pgCamelCase = require('pg-camelcase');
var revertCamelCase = pgCamelCaser(pg);
pg.connect(function(err, client, done){
client.query('select 1 as "some_snake_case"', function(err, res){
// should return all field names camel-cased
assert.strictEqual(res.row[0].someSnakeCase, 1);
done();
});
});
revertCamelCase(); // deactivate/revert the camel casing
pg.connect(function(err, client, done){
client.query('select 1 as "some_snake_case"', function(err, res){
// should not camel case anymore
assert.strictEqual(res.row[0].some_snake_case, 1);
done();
});
});If you run npm test and
TEST_PG_CONNECTION is setpg or pg.js is installedtests a running against an real server and the real result is checked. This should be the default for the tests on travis.