New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert column name format during migration #929
Comments
👍 |
There is currently no support for this in Though I'm not sure if this would be out of scope... To me I don't mind having that feature. Actually it would be pretty useful also for our project, which is based on |
Is there a better solution to this yet, other than manually transforming the object properties between camel and snake case every time? I'm using ES6 classes to model my tables and everything would work beautifully but for this. |
@prashaantt no there is currently no other way and it gets even more nasty than just converting them before inserting and after fetching rows. You would also need to convert all the column names passed to query's where clause. We ended up just using camelCase column names in our DB. |
So I suppose now you quote all your column names when writing raw SQL queries, right? Have you found it to be a fair compromise for most practical purposes? |
Knex does quoting itself e.g. |
Yes, raw SQL in the psql CLI is what I meant. Thanks for your insight. |
Closing in favor of #2084 which has some suggestion for initial implementation. |
Hi all, sorry to plug but I'm working on an ORM for knex which resolves this issue, PTAL https://github.com/joelmukuthu/knorm |
@joelmukuthu looks like it wraps pretty big part of knex API and limits it to use only |
@elhigu yeah, it wasn't fun to do that. it could also support |
I just implemented hook for postProsessingResults for the data read from DB. Docs are found here knex/documentation#58 So now with #2261 and #2217 this should be possible to do completely in knex side. |
@elhigu awesome, thank you! I'll try out the new hooks and provide some feedback, hopefully before 0.14 is out |
Hi,
In Bookshelf, I see that it's possible to override
parse()
andformat()
if you want to convert fromsnake_case
tocamelCase
and vice-versa when fetching or saving. Is there a similar method to do so in Knex? I'm running migrations where my table columns aresnake_case
, but I'm passing in an object where the properties arecamelCase
. I do realize that I can just change the property names tosnake_case
by wrapping it in quotes, but was hoping for something that I may override as can be done in Bookshelf.Thank you!
James
The text was updated successfully, but these errors were encountered: