As I mentioned in a blog post last week with Reactor and Spring WebFlux reactive programming has come to Java and the Spring platform.
R2DBC is relatively new project that aims to “to bring a reactive programming API to relational data stores“.
While currently still considered experimental, R2DBC endeavours to introduce reactive programming to how we access relational databases (reactive relational, hence the R2 in the name). This means that instead of the traditional way of querying SQL databases imperatively with prepared statements you’ll be able to write code such as
handle.execute("INSERT INTO test VALUES ($1)", 100))
handle.select("SELECT value FROM test")
.execute(result -> result.map((row, rowMetadata) -> row.get("value", Integer.class)))))
This’ll allow you to describe the desired behaviour declaratively and subscribe to new events generated by SQL result sets in a reactive fashion. Being able to deal with SQL result sets in a declarative manner is an interesting property because SQL itself is a declaratively language. Perhaps, using a declarative paradigm for processing SQL result can even help with alleviating the traditional impedance mismatch between relational and object-oriented data structures.
R2DBC currently provides database drivers for PostGreSQL, Microsoft SQL Server and the H2 in-memory database