Skip to content

Commit eb65939

Browse files
committed
Add examples for new bind/map methods on DatabaseClient
See gh-27282 See gh-26021
1 parent 3f79b26 commit eb65939

File tree

1 file changed

+40
-0
lines changed
  • framework-docs/modules/ROOT/pages/data-access

1 file changed

+40
-0
lines changed

framework-docs/modules/ROOT/pages/data-access/r2dbc.adoc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,25 @@ Kotlin::
254254
----
255255
======
256256

257+
Alternatively, there is a shortcut for mapping to a single value:
258+
259+
[source,java]
260+
----
261+
Flux<String> names = client.sql("SELECT name FROM person")
262+
.mapValue(String.class)
263+
.all();
264+
----
265+
266+
Or you may map to a result object with bean properties or record components:
267+
268+
[source,java]
269+
----
270+
// assuming a name property on Person
271+
Flux<Person> persons = client.sql("SELECT name FROM person")
272+
.mapProperties(Person.class)
273+
.all();
274+
----
275+
257276
[[r2dbc-DatabaseClient-mapping-null]]
258277
.What about `null`?
259278
****
@@ -324,6 +343,27 @@ The following example shows parameter binding for a query:
324343
.bind("age", 34);
325344
----
326345

346+
Alternatively, you may pass in a map of names and values:
347+
348+
[source,java]
349+
----
350+
Map<String, Object> params = new LinkedHashMap<>();
351+
params.put("id", "joe");
352+
params.put("name", "Joe");
353+
params.put("age", 34);
354+
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
355+
.bindValues(params);
356+
----
357+
358+
Or you may pass in a parameter object with bean properties or record components:
359+
360+
[source,java]
361+
----
362+
// assuming id, name, age properties on Person
363+
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
364+
.bindProperties(new Person("joe", "Joe", 34);
365+
----
366+
327367
.R2DBC Native Bind Markers
328368
****
329369
R2DBC uses database-native bind markers that depend on the actual database vendor.

0 commit comments

Comments
 (0)