quarkus

Configure datasource type at runtime


I have an application that uses a relational database and the database type is selected when the application is installed (between mysql, mariadb, mssql and oracle). The property quarkus.datasource.db-kind can only be defined at compile-time, so I don't really know how to get there without having to compile four copies of the same application. Any suggestion?

I understand why this should not be possible for a native image, but why is not possible even for a JIT artifact?

Marco.


Solution

  • As you have guessed correctly, this has been done to fully optimize the native executable case but it also allows for some optimizations in the JVM case. Quarkus does a lot of optimizations at build time and it needs to know the driver you're going to use at build time.

    FWIW, while people are disliking the answer and voting against it, this is the correct answer to the question. The fact that you don't like the answer doesn't make it an incorrect answer.

    There is something called reaugmentation that is used by Keycloak to have more flexibility: https://quarkus.io/guides/reaugmentation .

    We are also having discussions from time to time about allowing to include several drivers in your binaries and choose the driver at runtime but it is not done yet.

    You can subscribe to this issue if you want to follow the progress: https://github.com/quarkusio/quarkus/issues/43656 . You can also vote there to show us that it should be prioritized.