Add with_columns/2 to assign column names to fragment sources#4759
Add with_columns/2 to assign column names to fragment sources#4759greg-rychlewski wants to merge 7 commits into
Conversation
|
I had talked about it in discord but the reason why You could have some guarantees of some kind or ways to check but that is a pretty deadly footgun if someone changes the schema. I don't think that makes the |
|
Thank you @greg-rychlewski! I think the combination of PS: we may have discussed this already, apologies. |
|
Oh yes I think we could definitely do something like that. I was a bit unsure about it because it would be the only fragment helper that does not have a corresponding ? In the fragment string. Because we need to append it to the table identifier in the adapter (e.g f0 (col1, col2)). I am definitely not against it though because every solution has some kind of drawback. Let me know if I’m misunderstanding what you said though. |
|
Oh sorry I did misunderstand. Your example had it in the fragment string. So if you do it that way then we will get double “as” when the adapter creates the sql. And it could get tricky figuring out if the string has a table identifier/dealing with conflicts in the other autogenerated table names I’m still not against trying it out just letting you know why I opted out of that way |
|
So maybe we introduce it as syntax on |
|
Yeah that was the second main option I was considering seriously. We could call it column_names or something like that. The main thing I didn’t like is that you could not associate the columns right on the source like we do for values. And also I guess we don’t want to allow it outside fragments because the rest of the sources have their names handled automatically. But yeah that one and the one I submitted were the main 2 options I thought had the least drawbacks. I’m ok going with whichever one you like best |
In the doc for this function is the rationale for the feature.
I chose to create
with_columns/2instead of adding something like acolumnsoption tofrom/joinbecause I think the main use for this will be inside custom macros and for that it's nicer if it's attached directly to the source. It's also a simpler change.Ecto SQL companion: elixir-ecto/ecto_sql#743