0.1.0 • Published 4 years ago
@sprv/knex-case v0.1.0
@sprv/knex-case
Database columns case converter for Knex.
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
npm install @sprv/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('@sprv/knex-case')
const knex = Knex(withCase({
// knex configuration
}))
Advanced example:
const Knex = require('knex')
const { post, wrap } = require('@sprv/knex-case')
const knex = Knex({
// knex configuration
postProcessResponse (res) {
// custom post logic
return post(res)
},
wrapIdentifier (key, origImpl) {
// custom wrap logic
return wrap(key, origImpl)
}
})