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
Comment From: jhoeller
Note that this is available through paramSource(Object)
on the new JdbcClient
in 6.1. See #30931 and https://github.com/spring-projects/spring-framework/issues/26594#issuecomment-1678725276 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.
Comment From: jhoeller
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.
Comment From: jhoeller
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.