Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hoegaarden/pg-camelcase
camel-casing for postgres result field names
https://github.com/hoegaarden/pg-camelcase
Last synced: 3 months ago
JSON representation
camel-casing for postgres result field names
- Host: GitHub
- URL: https://github.com/hoegaarden/pg-camelcase
- Owner: hoegaarden
- Created: 2014-06-01T22:29:30.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-10T22:29:49.000Z (over 10 years ago)
- Last Synced: 2024-10-05T07:13:56.983Z (3 months ago)
- Language: JavaScript
- Size: 168 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
`pg-camelcase`
==============About
-----Changes 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:
```js
var pg = require('pg');
var pgCamelCase = require('pg-camelcase');
var revertCamelCase = pgCamelCase.inject(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();
});
});
```Tests
-----If you run `npm test` and
- the environment variable `TEST_PG_CONNECTION` is set
- `pg` 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.