Skip to content
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 dynamic SQL support for r2dbc #1649

Closed
wants to merge 3 commits into from
Closed

Add dynamic SQL support for r2dbc #1649

wants to merge 3 commits into from

Conversation

kfyty
Copy link

@kfyty kfyty commented Oct 24, 2023

I want to add dynamic SQL support for r2dbc, just like mybatis. Added the DynamicTemplateProvider interface, although it does not provide a default implementation, it provides a basic implementation. Users can fully implement this function using any third-party template framework, such as enjoy, freemarker, st, and so on.

@schauder do you have chance to take a look ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 24, 2023
@mp911de
Copy link
Member

mp911de commented Nov 9, 2023

Any SQL execution should be performed through the Template API instead of introducing another abstraction for query methods. It would make much more sense to explore how to encapsulate operations from the Repository to invoke a Template-based approach. Right now, operations use PreparedOperation where mapping happens to some extent in R2dbcQueryCreator.

@mp911de mp911de closed this Nov 9, 2023
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 9, 2023
@kfyty
Copy link
Author

kfyty commented Nov 10, 2023

I think many developers prefer to write SQL directly instead of using template APIs. In addition, currently there is still a lot of development space for template APIs

@mp911de
Copy link
Member

mp911de commented Nov 10, 2023

Using SQL queries is already possible via @Query so there's nothing that would prevent you from providing SQL yourself.

@kfyty
Copy link
Author

kfyty commented Nov 13, 2023

Yes, but I need to execute different SQL statements based on the conditions, such as adding mobile number filtering conditions when the parameter has a mobile number. I tried using spel, but it does not support control commands such as if else for. Moreover, the parameter binding of r2dbc is very strict, requiring strict consistency between SQL parameters and interface parameters, otherwise exceptions will occur. For example, if the SQL placeholder has a # {id}, and the interface method has an id and paging parameters, the call to the interface method will fail.

@holmofy
Copy link

holmofy commented May 15, 2024

@kfyty You can try using the spring-data-criteria library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants