kequc / knex-stringcase Goto Github PK
View Code? Open in Web Editor NEWHelper switches key case for npm knex
Home Page: https://www.npmjs.com/package/knex-stringcase
License: ISC License
Helper switches key case for npm knex
Home Page: https://www.npmjs.com/package/knex-stringcase
License: ISC License
E.g. when doing inserts to postgresql the raw response is an array of the inserted ids ([12]
). The case conversion breaks the response when trying to convert the keys of the array.
When plucking, snakecase vs camelcase returns different results:
knex('tablename').pluck('user_id') > [2, 3]
knex('tablename').pluck('userId') > [undefined, undefined]
Apparently this "plugin" also camelcasing the JSON inside the field of JSON type, which limits a lot of it uses.
As, I have some JSONs coming from third party modules, and I can "touch" them.
Hi,
I've updated to the latest version (1.1.0), and now the columns names are not converting to camelCase at all.
I've debugged it a bit, looks like this line always false
cause the object that knex returns has TextRow as a constructor.
Looks like this data type is what mysql2 returns, therefore the check for constructor is invalid.
Hi again,
I'm mostly looking for confirmation here regarding knex-stringcase whether it definitively converts pure knex.raw() queries to camelcase.
For the local testing I've worked through after pulling knex-stringcase into our project we can clearly see that one knex query which uses knex('table_name').select('column_one', 'column_two')
returns the field names as camelcase, yet when using the exact same query but with knex.raw('select column_one, column_two from table_name')
any field names returned are in snakecase.
The team and I here are wondering if this a bug or is this by design?
Expected results:
When using pure knex.raw('select column_one, column_two from table_name') queries the field names are returned as camelcase
Actual results:
When using pure knex.raw('select column_one, column_two from table_name') queries the field names are returned as snakecase
Versions:
First of all, thanks for the module.
It would be good to create TypeScript definitions for this.
Happy to contribute.
With 1.0.0, timestamptz columns returned an instance of Date
, but with 1.0.1, they return a plain object. For now, I am pinning to 1.0.0.
console.log(lastItem.createdAt);
2018-12-05T16:16:01.841Z
console.log(typeof lastItem.createdAt);
object
console.log(lastItem.createdAt instanceof Date);
true
console.log(lastItem.createdAt);
{}
console.log(typeof lastItem.createdAt);
object
console.log(lastItem.createdAt instanceof Date);
false
My package.json includes:
"pg": "^7.8.2",
"knex": "^0.16.3",
"knex-stringcase": "1.0.1",
I have a jsonb column which I insert an object {"foo_bar": "bar_foo"}
into.
The representation in the postgres database is {"foo_bar": "bar_foo"}
but when I pull the value out using knex and knex-stringcase, the object key gets converted to camelcase and I end up with {"fooBar": "bar_foo"}
.
The value does not change, only the key.
Is this intended to be the expected behavior?
I am using
knex v0.16.5
knex-stringcase v1.3.0
postgres 9.6.16
I love this plugin but I have a problem with it converting table names such as "order-rows_fields" to "order_rows_fields".
Is there a way to stop this for table names but keep it for column names?
Hi. I found that v1.2.0 is not backward compatible with v.1.1.x. When I try to build and run my project, the following error is being thrown.
"Cannot find module './build-converter.js'".
Thanks.
Hi,
Knex internally has some times (at migrations) usage of internal tables (such as information_schema
).
Those builtin tables has special cases (CONST_CASE), and because of the casting, knex fails on migrations. (trying to access TABLE_NAME
) but the object is camelCased.
There is any why to ignore those built in tables?
Is it possible to disable knex-stringcase for specific query?
ignoreStringcase
is not an option for me, cause I need raw column names only for one specific query, and convert this column names to camelCase in another queries.
Hi!
I have a very old specific database and was wondering whether it would be possible to discern between table names and column names namely I don't want my column names converted to upper case snake case, while I do want that for my columns. Would there be any way of achievingthis?
Thanks for the help!
Hi, I've encountered a problem when using knexStringcase
for sqlite3
in-memory db, the property Key is not parsed from snake case to camel case.
db = Knex(
knexStringcase({
client: "sqlite3",
connection: {
filename: ":memory:",
},
})
);
const result = db(table)
.select("*")
.where(where)
...
console.log(result[0]);
I got:
{
id: '00000000-0000-0000-0000-000000000003',
tenant_id: '94463c40-8e56-4afd-bee5-d2eda624bee9',
created_at: 1584368640000
}
It works correctly when using a real postgres
DB
Hi there,
We've recently pulled knex-stringcase into a project of ours and are enjoying it so far, with a couple oddities discovered.
The one I'm raising here is with respect to field names which include numbers in them. It appears as though if an underscore appears before a number then the underscore is not removed - although the rest of the string is snake to camel converted.
Expected results:
address_line_1
is changed to addressLine1
Actual results:
address_line_1
is changed to addressLine_1
Internally our app and API has addressLine1
defined for all our schemas. Our database as you can expect uses snakecase everywhere.
Versions:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.