Spring Data R2DBC

Spring Data R2DBC, part of the larger Spring Data family, makes it easy to implement R2DBC based repositories. R2DBC stands for Reactive Relational Database Connectivity, an incubator to integrate relational databases using a reactive driver. Spring Data R2DBC applies familiar Spring abstractions and repository support for R2DBC. It makes it easier to build Spring-powered applications that use relational data access technologies in a reactive application stack.

Spring Data R2DBC aims at being conceptually easy. In order to achieve this it does NOT offer caching, lazy loading, write behind or many other features of ORM frameworks. This makes Spring Data R2DBC a simple, limited, opinionated object mapper.

Spring Data R2DBC allows a functional approach to interact with your database providing DatabaseClient as the entry point for applications.

Get started by picking a database driver and create a DatabaseClient instance:

Postgres (io.r2dbc:r2dbc-postgresql)

H2 (io.r2dbc:r2dbc-h2)

Microsoft SQL Server (io.r2dbc:r2dbc-mssql)

PostgreSQL Example

PostgresqlConnectionFactory connectionFactory = new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder()
.host(…)
.database(…)
.username(…)
.password(…).build());

DatabaseClient client = DatabaseClient.create(connectionFactory);

Mono affectedRows = client.execute()
.sql(“UPDATE person SET name = ‘Joe’”)
.fetch().rowsUpdated();

Flux all = client.execute()
.sql(“SELECT id, name FROM person”)
.as(Person.class)
.fetch().all();

The client API provides covers the following features:

Execution of generic SQL and consumption of update count/row results.

Generic SELECT with paging and ordering.

SELECT of mapped objects with paging and ordering.

Generic INSERT with parameter binding.

INSERT of mapped objects.

Parameter binding using the native syntax.

Result consumption: Update count, unmapped (Map<String, Object>), mapped to entities, extraction function.

Reactive repositories using @Query annotated methods.

Transaction Management.

Spring Initializr
Quickstart Your Project
Bootstrap your application with Spring Initializr.

translate:
翻译:

Spring数据R2DBC是更大的Spring数据族的一部分,它使实现基于R2DBC的存储库变得更加容易。R2DBC代表反应性关系数据库连接,是使用反应性驱动程序集成关系数据库的孵化器。Spring数据R2DBC对R2DBC应用了熟悉的Spring抽象和存储库支持。它使得在被动应用程序堆栈中使用关系数据访问技术的Spring应用程序的构建更加容易。
Spring Data R2DBC的目标是概念上简单。为了实现这一点,它不提供缓存、延迟加载、write-behind或ORM框架的许多其他特性。这使得Spring数据R2DBC成为一个简单、有限、固执己见的对象映射器。
Spring Data R2DBC允许一种功能方法与数据库交互,提供DatabaseClient作为应用程序的入口点。
从选择数据库驱动程序并创建数据库客户端实例开始:
Postgres(io.r2dbc:r2dbc postgresql)
H2(io.r2dbc:r2dbc-H2)
Microsoft SQL Server(io.r2dbc:r2dbc mssql)
PostgreSQL示例
PostgresqlConnectionFactory connectionFactory=新建PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder()
。主机(…)
。数据库(…)
。用户名(…)

.password(…).build());
DatabaseClient client=DatabaseClient.create(连接工厂);
MonoaffectedRows=client.execute()
.sql(“更新人员集名称=‘Joe’”)
.fetch().rowsUpdated();
Fluxall=client.execute()
.sql(“从person中选择id,name”)
.as(人.类)
.fetch().all();
客户端API提供了以下特性:
执行通用SQL并使用更新计数/行结果。
带分页和排序的通用选择。
选择具有分页和排序的映射对象。
具有参数绑定的泛型插入。
插入映射对象。
使用本机语法的参数绑定。
结果消耗:更新计数,未映射(Map<String,Object>),映射到实体,提取函数。
使用@Query注释方法的反应式存储库。
交易管理。
弹簧初始化器
快速启动项目
使用Spring初始化器引导应用程序。

发布了0 篇原创文章 · 获赞 152 · 访问量 7071

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/105242518