| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
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:mysql) and org.testcontainers:r2dbc need to be on your application's classpath at runtime.
Original URL: r2dbc:mysql://localhost:3306/databasename
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=5.7.34
!!! 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:mysql:///databasename?TC_IMAGE_TAG=5.7.34
r2dbc:tc:mariadb:///databasename?TC_IMAGE_TAG=10.3.6
r2dbc:tc:postgresql:///databasename?TC_IMAGE_TAG=9.6.8
r2dbc:tc:sqlserver:///?TC_IMAGE_TAG=2017-CU12
If 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
| Back | FazBrowse Home | New Git URL |