Add DatabaseClient bind variant for list of parameters
Prior to this commit, the `DatabaseClient` interface would allow batch operations for binding parameters by their names and values. Positional parameters did not have such equivalent. This commit adds a new `bindValues(List<?>)` method variant for adding multiple positional arguments in a single call and avoiding allocation overhead when the parameters count is large. Closes gh-33274
This commit is contained in:
@@ -364,6 +364,28 @@ Or you may pass in a parameter object with bean properties or record components:
|
||||
.bindProperties(new Person("joe", "Joe", 34);
|
||||
----
|
||||
|
||||
Alternatively, you can use positional parameters for binding values to statements.
|
||||
Indices are zero based.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
|
||||
.bind(0, "joe")
|
||||
.bind(1, "Joe")
|
||||
.bind(2, 34);
|
||||
----
|
||||
|
||||
In case your application is binding to many parameters, the same can be achieved with a single call:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
List<?> values = List.of("joe", "Joe", 34);
|
||||
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
|
||||
.bindValues(values);
|
||||
----
|
||||
|
||||
|
||||
|
||||
.R2DBC Native Bind Markers
|
||||
****
|
||||
R2DBC uses database-native bind markers that depend on the actual database vendor.
|
||||
|
||||
Reference in New Issue
Block a user