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.

发布了0 篇原创文章 · 获赞 135 · 访问量 5697
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览