GithubHelp home page GithubHelp logo

mkhanal / knex-case-converter-plugin Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 171 KB

Knexjs - convert snake_case column names to camelCase on query and the reverse when using parameters

License: GNU General Public License v3.0

JavaScript 100.00%
knexjs database case-converter case-conversion nodejs

knex-case-converter-plugin's Introduction

knex-case-converter-plugin

Build Status Coverage Downloads Downloads npm version dependencies dev dependencies License

convert snake_case column names to camelCase on query and the reverse when using parameters

Getting Started

Install it via npm:

npm install knex-case-converter-plugin

Or Yarn it:

yarn add knex-case-converter-plugin

And include in your project:

import plugin from 'knex-case-converter-plugin';

//sample
let knexConfig = {
  "client": "mysql2",
  "debug": true,
  "connection": {
    "host": "localhost",
    "user": "root",
    "password": "root",
    "database": "db_test"
  }
}

Object.assign(knexConfig, plugin)
// OR
//knexConfig.wrapIdentifier = plugin.wrapIdentifier;
//knexConfig.postProcessResponse = plugin.postProcessResponse;

License

GPL-3.0

knex-case-converter-plugin's People

Contributors

dependabot[bot] avatar mkhanal avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

knex-case-converter-plugin's Issues

Plugin does not update the model attributes on save

When a record will be saved then the save promise doesn't return anymore the model which contains the attributes from the database (id remains undefined...)

const response = await Role.forge({
      title: '12',
      active: 1,
    }).save();


ModelBase {
  attributes: [Object: null prototype] { title: '12', active: 1 },
  _previousAttributes: {},
  changed: [Object: null prototype] {},
  relations: {},
  cid: 'c1',
  _knex: null,
  id: undefined
}

Plugin doesn't seem to work with .raw()

Have you run into any issues where writing queries with knex.raw(...) don't return converted rows?

Currently if I do a query like

database.raw(`
      SELECT associate.*, market_id
      FROM associate
      JOIN store ON store.id = associate.store_id
      JOIN market ON market.id = store.market_id
      WHERE associate.active = true
      AND market.id = ${marketId}
`);

the rows getting returned have fields like market_id.

where when I run the query using knex methods like

database('associate')
      .join('store', 'store.id', '=', 'associate.store_id')
      .join('market', 'market.id', '=', 'store.market_id')
      .where('associate.active', '=', active)
      .andWhere('market.id', '=', marketId)
      .select('associate.*', 'market_id');

the rows returned have camelcase fields like marketId

I am not sure if I am doing anything wrong, any insight would be appreciated.
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.