Package org.springframework.r2dbc.core
Interface DatabaseClient
- All Superinterfaces:
ConnectionAccessor
A non-blocking, reactive client for performing database calls requests with
Reactive Streams back pressure. Provides a higher level, common API over
R2DBC client libraries.
Use one of the static factory methods create(ConnectionFactory)
or obtain a builder()
to create an instance.
Usage example:
ConnectionFactory factory = … DatabaseClient client = DatabaseClient.create(factory); Mono<Actor> actor = client.sql("select first_name, last_name from t_actor") .map(row -> new Actor(row.get("first_name, String.class"), row.get("last_name, String.class"))) .first();
- Since:
- 5.3
- Author:
- Mark Paluch
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A mutable builder for creating aDatabaseClient
.static interface
Contract for specifying an SQL call along with options leading to the execution. -
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseClient.Builder
builder()
Obtain aDatabaseClient
builder.static DatabaseClient
create
(ConnectionFactory factory) Create aDatabaseClient
that will use the providedConnectionFactory
.Return theConnectionFactory
that this client uses.Specify a staticsql
statement to run.Specify aSQL supplier
that provides SQL to run.Methods inherited from interface org.springframework.r2dbc.core.ConnectionAccessor
inConnection, inConnectionMany
-
Method Details
-
getConnectionFactory
ConnectionFactory getConnectionFactory()Return theConnectionFactory
that this client uses.- Returns:
- the connection factory
-
sql
Specify a staticsql
statement to run. Contract for specifying a SQL call along with options leading to the execution. The SQL string can contain either native parameter bind markers or named parameters (e.g. :foo, :bar) whenNamedParameterExpander
is enabled.- Parameters:
sql
- the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec
- See Also:
-
NamedParameterExpander
DatabaseClient.Builder.namedParameters(boolean)
-
sql
Specify aSQL supplier
that provides SQL to run. Contract for specifying an SQL call along with options leading to the execution. The SQL string can contain either native parameter bind markers or named parameters (e.g. :foo, :bar) whenNamedParameterExpander
is enabled.Accepts
PreparedOperation
as SQL and bindingSupplier
- Parameters:
sqlSupplier
- a supplier for the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec
- See Also:
-
NamedParameterExpander
DatabaseClient.Builder.namedParameters(boolean)
PreparedOperation
-
create
Create aDatabaseClient
that will use the providedConnectionFactory
.- Parameters:
factory
- theConnectionFactory
to use for obtaining connections- Returns:
- a new
DatabaseClient
. Guaranteed to be notnull
.
-
builder
Obtain aDatabaseClient
builder.
-