DEV Community

Luis Fabrício De Llamas
Luis Fabrício De Llamas

Posted on

Dev Services for Databases

Image description

Quarkus Dev Services for Java Developers.

When it comes to Java development, agility and efficiency are crucial. One of the challenges developers face is configuring and managing databases for their applications. Quarkus, a modern and efficient Java framework, provides an elegant solution to this problem with its "Dev Services" functionality for databases.

What Are Dev Services?

Dev Services are a feature of Quarkus that allow developers to have a fully configured and ready-to-use database without the need for complex configurations. This is particularly valuable during development and testing when agility is paramount. Quarkus supports various types of databases, including PostgreSQL, MySQL, MariaDB, H2, and others. Here are some of the benefits:

Zero Configuration

You don't need to manually configure the database URL, username, and password in your application. Quarkus does this automatically for you, saving you time and effort.

Automatic Startup

Dev Services automatically start a database server in development mode and during testing. This means you don't need to manually start a server. The application is configured automatically.

Ease of Use

To use Dev Services, simply include the relevant extension for the type of database you want to use (reactive or JDBC). No need to configure a database URL, username, and password. Quarkus provides the database, and you can start coding without worrying about settings.

Configuration Examples for PostgreSQL:

Enabling / Disabling Dev Services for the Database:

You can disable the automatic start of the Dev Services database in the application.properties file using the following configuration:

properties

quarkus.datasource.devservices.enabled=false

License Acceptance for Proprietary Databases:

If you are using a proprietary database such as DB2 or MSSQL, you will need to accept the license agreement. Create a container-license-acceptance.txt file in your project and add the image name and tag of the database, as shown in the example:

properties

src/main/resources/container-license-acceptance.txt

ibmcom/db2:11.5.0.0a
mcr.microsoft.com/mssql/server:2017-CU12

Mapping Volumes for Database Data Persistence:

You can map volumes from the Docker host's filesystem to containers to provide files such as scripts or configurations and to preserve database data. Here's an example:

properties

quarkus.datasource.devservices.volumes."/path/from"=/container/to

In the above example, the directory "/path/from" on the local machine is accessible at "/container/to" in the container.

Connecting to a Database Running as a Dev Service:

You can connect to a database running as a Dev Service in the same way you would with any database running inside a Docker container.

Configuration Reference:

Quarkus offers a wide range of configuration options to meet your project's specific needs. Here are some of the available configuration options:

quarkus.datasource.devservices.enabled: Allows you to explicitly enable or disable Dev Services.
quarkus.datasource.devservices.image-name: Sets the name of the container image to be used.
quarkus.datasource.devservices.container-env: Allows you to set environment variables to be passed to the container.
quarkus.datasource.devservices.container-properties: Allows you to set specific database properties for additional container configuration.
quarkus.datasource.devservices.port: Defines an optional fixed port for the Dev Service instead of a random port.
quarkus.datasource.devservices.init-script-path: Specifies a path to an SQL script to be loaded from the classpath and applied to the Dev Service database.

These configurations can be adjusted according to your project's needs, providing flexibility in using Quarkus Dev Services.

In summary, Quarkus Dev Services significantly simplifies the process of configuring and managing databases for Java developers. With minimal setup, you can start developing and testing your applications quickly and efficiently, saving time and effort. It's a valuable tool for enhancing productivity and accelerating Java application development.

Top comments (1)

Collapse
 
dellamas profile image
Luis Fabrício De Llamas

Link for the community Quarkus Club
discord.gg/8VGwRtf6sm