0.3.1 • Published 5 years ago

@spridev/knex-case v0.3.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

knex-case

npm version npm downloads npm dependencies JavaScript Style Guide

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:

  1. By overriding the postProcessResponse and wrapIdentifier methods completely.
  2. By calling the post and wrap 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);
    }
});
0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago