micronaut-projects / micronaut-projects/micronaut-data
Support expression in queries
- Dominant language
- Java
- Stars
- 482
- Forks
- 229
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 32
Description
We need to delegate resolving table or parameters at runtime. (This is happening mostly when we are using a generic interface or dynamic parameters. I have simplified this part for the sake of simplicity)
> @Query("SELECT * FROM #tablename WHERE name LIKE :name")
> List findByName(String tablename, String name);
I was considering a better approach for this and I came across "property placeholder" concept. Maybe we can create a context from current invocation, parameters and instance and resolve it. My query can become like this:
> @Query("SELECT * FROM ${tablename} WHERE name LIKE :name")
> List findByName(String tablename, String name);
Or for another example
> @Query("SELECT * FROM ${t.simpleName} WHERE name LIKE :name")
> List findByName(Class t, String name);
Or
> @Query("SELECT * FROM ${clazz.simpleName} WHERE name LIKE :name")
> List findByName(Class clazz, String name);
What do you think?
Contributor guide
Research direction
Start by tracing the @Query repository entry point and how query text, method parameters, and runtime context are currently handled. Define the supported expression scope and verify that table or parameter values resolve at invocation time without breaking existing named-parameter binding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100