In R2DBC, ConnectionFactory from the io.r2dbc.spi package is the reactive equivalent of a DataSource in JDBC. It is responsible for producing non-blocking Connection instances that support reactive and coroutine-based database access.
In Exposed, the exposed-r2dbc module integrates R2DBC support by allowing you to connect to a database using a ConnectionFactory. This is done implicitly through the R2dbcDatabase.connect() function whenever a URL is passed:
When a URL is passed to R2dbcDatabase.connect(), the string is parsed to construct a new ConnectionFactoryOptions object, which holds details of the configuration state related to the ConnectionFactory.
This state can be configured manually, using the R2dbcDatabaseConfig.connectionFactoryOptions builder, either alongside a provided URL:
You can also pre-construct a ConnectionFactoryOptions object and use it to initialize a custom R2dbcDatabaseConfig instance. You can then pass both directly to R2dbcDatabase.connect() at a later point:
To connect Exposed to a database using R2DBC, you can optionally rely on manual programmatic connection factory discovery by providing an explicit ConnectionFactory. This connection source can then be passed to the R2dbcDatabase.connect() function:
For simplicity or for more fine-tuned connection customization, you can use database-specific connection factories and configuration builders via programmatic configuration. These database-specific objects can be created and passed in the same way as the general R2DBC SPI objects: