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:
Brian Clozel
2024-07-29 14:07:15 +02:00
parent 1f2c6c33ac
commit 38453910cd
4 changed files with 70 additions and 1 deletions

View File

@@ -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.