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
Add option of existingType to .enum method to support repeated use of enums #2719
Conversation
I second this proposition and motion for a move to merge :P |
Sounds reasonable, I cannot think any better API for handling this situation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tests and documentation (specially intregration test will be important to see that this works the same way with other dialects supporting native enum)
@ekeric13 Would you consider finishing this PR? |
Yeah for sure. @heisian and I have a working implementation, just need to write tests for it. |
Awesome! Also PR for documentation in https://github.com/knex/documentation would be most appreciated :) |
Okay, @kibertoad added some tests. Corresponding Docs: knex/documentation#147 Since it is just using an existing type, we could allow the api to be
As it is a bit weird to have to specify an array of values that aren't actually going to be used (since the type is already created, it just utilizes the The code would need to be changed to something like so:
Finally it looks like we are still getting a drop in code coverage. I can add more tests, but they would be like "expect error when x" tests. |
@ekeric13 Thank you very much! It's 0:30 here already, it was a long day; I'll take a look at it tomorrow and comment ASAP, sorry for the delay. |
So what is the process after this? Just will be merged in for the next release? |
@ekeric13 Probably can be merged within 0.16.0 window, but before that I assume we should consider the alternative improved syntax that you've suggested?.. |
@ekeric13 Looked at previous and current syntax and I think that it makes perfect sense, would you do the change? |
Okay, added the proposed ternary operator to make the function type agnostic of the values in the case where the values aren't being used. Updated the docs as well for further clarification: |
@ekeric13 Awesome work, thank you! |
🎊 |
… enums (knex#2719) * Update table column .enu to take an option that does not manually create the type * Add tests for psql enum existingType * Avoid utilizing enum values when using an existing type
I was super happy to see knex supporting native enums in postgres, but when I had an enum that I used repeatedly across different columns in different tables, I was running into errors as the
enum
method created the type enum for you each time. The type would already exist so it would error. I only wanted to create the type once, afterwards I just wanted to use that enum.Could we add a flag in the options param to not run the sql that creates the type enum?
The first time you run it you could do
And then the other times you can run