-
Notifications
You must be signed in to change notification settings - Fork 197
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
Dynamic query criteria #89
Comments
This is the same concept more or less of specifications in Spring Data JPA. We may at some point support these, but it is undecided whether to do so at compilation time or runtime query computation. |
This approach is more flexible than Spring Data JPA, where the query is hard-coded in the method name. So if you need to filters entities by created time in some case greater than and in some case less than, we need to have 2 methods, and choose one of depending on that user sends to us. That I am proposing is to generate a method at compile time that will create the query at run-time based on the parameters passed to this method. In this case, a lot of boilerplate will be eliminated. |
I am thinking of something like
|
Any feedback about he approach? |
@raderio Thanks for the feedback, yes a DSL like that would probably be nice and something we can consider in the future. We certainly need a "Criteria"-like API to allow for dynamic queries as well as static queries. We first want to get the initial support for static queries stable and released however, so this one is definitely on the radar for the future. |
Does this framework make any reference sense? |
Could there be any progress or plans during 2021?🤔️ |
@chenjpu Are you looking for JPA or JDBC/R2DBC criteria? |
@dstepanov JDBC/R2DBC criteria |
I will investigate possible solutions for release 3.2 |
@dstepanov rather than build a new API might be worthy integrating QueryDSL or Immutables |
I have seen a PR has merged and when will version 3.2 be released? |
This week |
1.How to set the parameter ???
2.Otherwise the following error
|
@dstepanov Is there any documentation for the above question? |
There is an official link to the JPA criteria API https://micronaut-projects.github.io/micronaut-data/latest/guide/#dbcCriteriaSpecifications There are some examples in the repo https://github.com/micronaut-projects/micronaut-data/blob/master/doc-examples/jdbc-example-java/src/main/java/example/PersonRepository.java |
Closing this issue as there is a way to use the criteria |
@dstepanov Thanks for this quick reply!Very sorry,Maybe my question is not clear.
In the Criteria API mode,how to make name bind as parameter instead of directly in sql, like below
|
@chenjpu We don't support that case yet. Can you please describe why are you using 2. and why parameter-binding is something you want to have? |
Prepare to plan to migrate from the mybatis framework to microanut-data, the previous business has a dynamic query requirements, want to achieve through the Criteria API mode |
In the query parameter, may include the ' character, if the parameter binding mode is not supported, the user's query will appear sql error. |
Are you reporting that the |
The query string does not do any escaped |
Please fill a new issue |
@dstepanov |
@chenjpu I will try to improve it after the next release |
At the moment query criteria is hard coded in the method name, so if we need in some cases to find products by created time starts with, and in another case to find products by created time ends with, we need to have 2 methods.
As solution can be dynamic query criteria
In this case we can have just one method for searching and cover all the cases.
This solution is just an alternative way, it doesn't mean the actual approach should be deleted.
Also, we can add sorting
And we also can add some annotation to method parameters to configure more specific projection if needed.
The text was updated successfully, but these errors were encountered: