docs/modules/databases/r2dbc.md
You can obtain a temporary database in one of two ways:
As long as you have Testcontainers and the appropriate R2DBC driver on your classpath, you can simply modify regular R2DBC connection URLs to get a fresh containerized instance of the database each time your application starts up.
The started container will be terminated when the ConnectionFactory is closed.
!!! warning
Both the database module (e.g. org.testcontainers:testcontainers-mysql) and org.testcontainers:testcontainers-r2dbc need to be on your application's classpath at runtime.
Original URL: r2dbc:mysql://localhost:3306/databasename
tc: after r2dbc: as follows. Note that the hostname, port and database name will be ignored; you can leave these as-is or set them to any value.TC_IMAGE_TAG query parameter.Note that, unlike Testcontainers' JDBC URL support, it is not possible to specify an image tag in the 'scheme' part of the URL, and it is always necessary to specify a tag using TC_IMAGE_TAG.
So that the URL becomes:
r2dbc:tc:mysql:///databasename?TC_IMAGE_TAG=8.0.36
!!! note
We will use /// (host-less URIs) from now on to emphasis the unimportance of the host:port pair.
From Testcontainers' perspective, r2dbc:mysql://localhost:3306/databasename and r2dbc:mysql:///databasename is the same URI.
!!! warning If you're using the R2DBC URL support, there is no need to instantiate an instance of the container - Testcontainers will do it automagically.
r2dbc:tc:clickhouse:///databasename?TC_IMAGE_TAG=21.11.11-alpine
r2dbc:tc:mysql:///databasename?TC_IMAGE_TAG=8.0.36
r2dbc:tc:mariadb:///databasename?TC_IMAGE_TAG=10.3.39
r2dbc:tc:postgresql:///databasename?TC_IMAGE_TAG=9.6.8
r2dbc:tc:sqlserver:///?TC_IMAGE_TAG=2017-CU12
r2dbc:tc:oracle:///?TC_IMAGE_TAG=21-slim-faststart
ConnectionFactoryOptions from database container objectsIf you already have an instance of the database container, you can get an instance of ConnectionFactoryOptions from it:
Creating ConnectionFactoryOptions from an instance) inside_block:get_options