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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA mutable builder for creating aDatabaseClient.static interfaceContract for specifying an SQL call along with options leading to the execution. -
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseClient.Builderbuilder()Obtain aDatabaseClientbuilder.static DatabaseClientcreate(ConnectionFactory factory) Create aDatabaseClientthat will use the providedConnectionFactory.Return theConnectionFactorythat this client uses.Specify a staticsqlstatement to run.Specify aSQL supplierthat provides SQL to run.Methods inherited from interface org.springframework.r2dbc.core.ConnectionAccessor
inConnection, inConnectionMany
-
Method Details
-
getConnectionFactory
ConnectionFactory getConnectionFactory()Return theConnectionFactorythat this client uses.- Returns:
- the connection factory
-
sql
Specify a staticsqlstatement 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) whenNamedParameterExpanderis enabled.- Parameters:
sql- the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec - See Also:
-
NamedParameterExpanderDatabaseClient.Builder.namedParameters(boolean)
-
sql
Specify aSQL supplierthat 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) whenNamedParameterExpanderis enabled.Accepts
PreparedOperationas SQL and bindingSupplier- Parameters:
sqlSupplier- a supplier for the SQL statement- Returns:
- a new
DatabaseClient.GenericExecuteSpec - See Also:
-
NamedParameterExpanderDatabaseClient.Builder.namedParameters(boolean)PreparedOperation
-
create
Create aDatabaseClientthat will use the providedConnectionFactory.- Parameters:
factory- theConnectionFactoryto use for obtaining connections- Returns:
- a new
DatabaseClient. Guaranteed to be notnull.
-
builder
Obtain aDatabaseClientbuilder.
-