Skip to content

Commit

Permalink
Add examples for new bind/map methods on DatabaseClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Aug 16, 2023
1 parent 3f79b26 commit eb65939
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions framework-docs/modules/ROOT/pages/data-access/r2dbc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@ Kotlin::
----
======

Alternatively, there is a shortcut for mapping to a single value:

[source,java]
----
Flux<String> names = client.sql("SELECT name FROM person")
.mapValue(String.class)
.all();
----

Or you may map to a result object with bean properties or record components:

[source,java]
----
// assuming a name property on Person
Flux<Person> persons = client.sql("SELECT name FROM person")
.mapProperties(Person.class)
.all();
----

[[r2dbc-DatabaseClient-mapping-null]]
.What about `null`?
****
Expand Down Expand Up @@ -324,6 +343,27 @@ The following example shows parameter binding for a query:
.bind("age", 34);
----

Alternatively, you may pass in a map of names and values:

[source,java]
----
Map<String, Object> params = new LinkedHashMap<>();
params.put("id", "joe");
params.put("name", "Joe");
params.put("age", 34);
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
.bindValues(params);
----

Or you may pass in a parameter object with bean properties or record components:

[source,java]
----
// assuming id, name, age properties on Person
db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)")
.bindProperties(new Person("joe", "Joe", 34);
----

.R2DBC Native Bind Markers
****
R2DBC uses database-native bind markers that depend on the actual database vendor.
Expand Down

0 comments on commit eb65939

Please sign in to comment.