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

R2DBC - DatabaseClient - Add bind method to accept an object #27282

Closed
kitkars opened this issue Aug 15, 2021 · 3 comments
Closed

R2DBC - DatabaseClient - Add bind method to accept an object #27282

kitkars opened this issue Aug 15, 2021 · 3 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@kitkars
Copy link

kitkars commented Aug 15, 2021

Hi R2DBC team,

This is a feature request.

Currently with DatabaseClient we can execute any arbitrary SQL statement which is cool. Can we add an additional overloaded method for bind ?

If I have to pass multiple parameters, instead of passing them one by one using the current bind method like .bind("firstName", "somename").bind("lastName", "somename")...

can we make the method to accept an object as well as show below? Just an additional method to simply this.

class BindInput {

    private String firstName;
    private String lastName;
    private String email;
    ...
    ...
}

.bind(bindInput); // pass a POJO object

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 15, 2021
@rstoyanchev rstoyanchev added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Nov 10, 2021
@jhoeller jhoeller added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 15, 2023
@jhoeller jhoeller added this to the 6.1.x milestone Aug 15, 2023
@jhoeller
Copy link
Contributor

Note that this is available through paramSource(Object) on the new JdbcClient in 6.1. See #30931 and #26594 (comment) for the context there.

Unfortunately, this is not totally straightforward to provide with the R2DBC DatabaseClient since the BindParameterSource mechanism is not exposed there. We'll see what we can do about this.

@jhoeller
Copy link
Contributor

I'm introducing a bindProperties(Object) method on DatabaseClient, supporting bean properties and record components for named parameter determination. This is implemented directly in DatabaseClient without going through a custom BindParameterSource.

Note that plain field holders are not supported since this is not idiomatic with R2DBC. Record classes or custom classes with constructors and/or bean-style accessors can be very concise and are actually better suited for inline use in a reactive pipeline.

@jhoeller
Copy link
Contributor

jhoeller commented Aug 16, 2023

For completeness, I'm also introducing a bindValues(Map) method which accepts names as map keys and scalar values or Parameter objects as map values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants