0.3.1 • Published 5 years ago
@spridev/knex-case v0.3.1
knex-case
Knex extension to convert database column names, because you may want to use snake_cased names in database and camelCased names in code.
The conversion is done using knex's postProcessResponse and wrapIdentifier hooks.
Installation
knex-case can be installed using npm
or yarn
.
npm install @sprdv/knex-case
Usage
This extension can be used in two different ways:
- By overriding the
postProcessResponse
andwrapIdentifier
methods completely. - By calling the
post
andwrap
methods in your own knex hooks.
Simple example:
const Knex = require('knex');
const { withCase } = require('@sprdv/knex-case');
const knex = Knex(withCase({
// knex configuration
}));
Advanced example:
const Knex = require('knex');
const { post, wrap } = require('@sprdv/knex-case');
const knex = Knex({
// knex configuration
postProcessResponse: function(res) {
// custom post logic
return post(res);
},
wrapIdentifier: function(key, origImpl) {
// custom wrap logic
return wrap(key, origImpl);
}
});