quarkiverse / quarkus-jdbi

Jdbi provides convenient, idiomatic access to relational data in Java
https://jdbi.org/
Apache License 2.0
13 stars 4 forks source link

Declarative Configuration Support and DSL Integration #99

Open ghost opened 6 months ago

ghost commented 6 months ago

Description

Currently, configuring Jdbi involves some manual setup, which can be cumbersome and error-prone, especially in complex environments with multiple datasources and varying plugin requirements. To streamline this process, a declarative configuration approach that automatically configures the Jdbi setup within Quarkus could help to reach a common baseline:

In other words, the following class:

import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.Slf4JSqlLogger;
import org.jdbi.v3.sqlobject.SqlObjectPlugin;

import javax.sql.DataSource;

public class PersistenceConfig {
  @Inject
  DataSource dataSource;

  @Produces
  @Singleton
  public Jdbi jdbi() {
    return Jdbi.create(dataSource).installPlugin(new SqlObjectPlugin()).setSqlLogger(new Slf4JSqlLogger());
  }
}

Could be automatically configured whenever a datasource configuration is enabled — with the exception of the plugins and the SQL logger.