-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 splice to fragment
#4228
Add splice to fragment
#4228
Conversation
I just realized they are not being collected as parameters. I could see if that could be handled in the planner but not sure about MySQL because it uses edit: Now I'm really doubting this feature is viable. If we want to collect the parameters in the planner then we need to traverse all the exprs before hitting the cache. And we don't want to do that. And I don't think this is a good idea without collecting them as parameters because then the # of cached queries could explode. Probably I need to think if there is a completely other way to do something like this. Or maybe the query can just not be cached when using this. If that's a thing. |
I think something like this could work actually. edit: no actually it can't. sorry for the noise. |
Would it make a difference if we use the notation inside the fragment? Something like "(?, *?, ?)"? |
This reverts commit f18938d.
I believe it will be the same issue. It looks to me like the underlying issue is being able to convert a runtime list from a single param to a dynamic number of params. WTDY of something like this? I am trying to "flag" the parameters so that they can be treated properly at runtime if needed. Probably this is not a good flag but was just curious what you thought of the general idea? P.S If this is ok then actually I like your inline syntax better. I think the same strategy can be done for that. Maybe need to think a bit if people would commonly use |
Honestly, it has been a while since I played with this, so I cannot quite recall. What i remember is that each list length becomes a different cached query. You can look at how MyXQL handles this, because they support variadic |
Oh I see it now. Thank you for pointing me to that. |
This reverts commit fa3f5c6.
WDYT about this way? If it's good I can add the docs. Companion ecto sql PR: elixir-ecto/ecto_sql#535 |
LGTM! Please don't forget to add splice to Ecto.Query.API as well. :) |
This is a proposal to add a splice capability to
fragment
. It is taking inspiration fromliteral/1
as well asunquote_splicing
.The idea is that the user would supply a list argument to
fragment
and then this would be spliced into the query string. Something like thisThere are several use cases where this could come in handy:
fragment
when you require a variable number of arguments. For example changing thewhere
operator behaviour: Switch to using = ANY(SELECT unnest(?)) instead of = ANY(?) for IN operator #2570 (comment)VALUE
lists that might have different sizes.If the proposal is accepted I could finish up the PR. Just didn't want to get ahead of myself before receiving feedback.