-
Notifications
You must be signed in to change notification settings - Fork 107
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
Nesting of aql templates #481
Comments
Currently queries are not composable, yes. This is a known limitation because merging bindVars is nontrivial. Supporting this would likely require scanning the argument list for AQL objects and prepopulating the bindVars so the numbers remain consistent. However this suggest we should also mark the AQL objects so we know they're actual AQL objects and can be trusted (unlike user input). I'm not 100% sure this is a good idea but composability beyond simple |
Wow, I was just looking for something like this. |
We're investigating a possible implementation of this, which may land in the upcoming 6.0.0 release. |
Ya this is exactly what we need. How is the progress? |
It's more complicated than initially anticipated. The problem is that nesting I'm scheduled to be back in office next week, so I'll look into it again then. |
Just an update: this is definitely non-trivial and not easy to solve, especially when considering deeply nested queries with bindvars. As this isn't currently a high priority issue, we've decided to shelve the idea for the time being. |
@Brian-McBride I needed something similar and came up with this. @pluma, I know that the benefit of using the To elaborate: My example creates a string that looks like
then calls
Is there anything unsafe about this? |
Thanks for sharing that, @good-idea. Pagination is turning out to be a huge bitch with arango, I really liked your example. @pluma Just wanted to chime in that I share the same use case. Even just being able to dynamically add a statement would be of huge benefit, ie
Would it be possible to null check the arg at least?
would be treated safe |
This has been implemented and will be part of the next release. This means the following (adapted from @JonDum's example) will be possible: let filter = args.eventOnly ? aql`FILTER i % 2 == ${args.reversed ? false : true}` : undefined;
db.query(aql`FOR i IN 1..10 ${filter} RETURN i`); Note that this correctly merges the bindVars See the CHANGELOG for details. |
Thank you, @pluma ! 🎊 |
That's awesome! You rock @pluma! |
Is there an ETA for the next release? And will the aql template present in transactions will also work like this? |
@alewaros Transactions are executed on the server, so the ArangoDB version needs to support this as well. As far as I'm aware this feature isn't being backported to 3.3, so you need to use 3.4 or later. If you're using v3.4.0-rc2 or later, you can already give it a try. For production I recommend waiting for the regular release of 3.4.0. I'm back from vacation and will work on dirty reads support this week. The current plan is for the next arangojs release to happen shortly before 3.4.0 GA. |
Hello,
For complexe queries, aql templates seems to be a bit tricky to use. Maybe the best way is to use query builder. But, I think recursivity may help.
For exemple :
Or maybe the simplest exemple :
Is it a good idea ? Probably not. But, may help in some cases like mine.
For now, I've done the job without aql template, but the result may be less safe (here, id are not from user input)
Have a nice day,
Gaël
The text was updated successfully, but these errors were encountered: