Service Provider Interface (SPI)
R2DBC defines an SPI all data store drivers must implement.
- r2dbc-spi: a set of interfaces defining the SPI for R2DBC.
- r2dbc-spi-test: within the SPI repository, a Technology Compatibility Kit (TCK) for verifying a driver’s implementation.
One noticeable difference between R2DBC and JDBC is that JDBC is aimed at both driver writers and application developers. Driver developers and application developers operate at different levels, making this one-size-fits-all model less than ideal.
R2DBC’s SPI is deliberately designed to be as small as possible, while still including features critical for any relational data store. This means that the SPI does not target extensions which are specific to a data store.
To ease implementation, R2DBC also provides a test interface (a veritable TCK) to ensure your driver is fully operational.
R2DBC drivers implement the SPI listed above. The ones currently supported include:
- cloud-spanner-r2dbc - driver for Google Cloud Spanner.
- jasync-sql - R2DBC wrapper for Java & Kotlin Async Database Driver for MySQL and PostgreSQL (written in Kotlin).
- r2dbc-h2 - native driver implemented for H2 as a test database.
- r2dbc-mariadb - native driver implemented for MariaDB.
- r2dbc-mssql - native driver implemented for Microsoft SQL Server.
- r2dbc-mysql - native driver implemented for MySQL.
- r2dbc-postgres - native driver implemented for PostgreSQL.
The following connection pool implementations are available for R2DBC:
- r2dbc-pool - reactive connection pooling using Reactor Pool.
Implementing a Driver
R2DBC has a clearly-defined SPI, which you must implement to host a solution for your data store. To build an implementation, add the following artifact to your build:
There are other parts to implement, but this is the core.
Technology Compatibility Kit (TCK)
R2DBC also has a suite of test cases to verify your driver’s support. Your data store implementation should import a test-scoped dependency on the following artifact:
To run all of the expected tests, write an implementation of the TCK’s
See the example in r2dbc-postgresql to read the full source.