Add support for using Term as query in run_query() #2796
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces a feature that was discussed quite a bit before (#2465 (comment), #2500 (reply in thread), #2637 (comment)): using a structured
Term
instead of a wobbly string for queries. This makes it easier to procedurally generate queries, and also provides a good way to avoid injection attacks.In the way I implemented,
Machine::run_query()
can now accept either (things that can be turned into) strings or aTerm
. A simple example (taken from the tests):This could get even more ergonomic if we eventually make macros for creating
Term
s (though I think it would have a lot of limitations on the allowed syntax). Imagine:After doing this I'm really glad we are getting rid of
parser::ast::Term
in rebis-dev, because that type is a mess! However, from what I've read of the rebis-dev branch, it not existing will probably make this feature a bit harder to implement.This also serves as even more incentive to base the C embedding interface on a
Term
based API instead of on top of JSON serialization.