Jdbi provides convenient, idiomatic access to relational data in Java This quarkus extension makes it possible to use JDBI in native executables.
Add the following dependency in your pom.xml to get started,
<dependency>
<groupId>io.quarkiverse.jdbi</groupId>
<artifactId>quarkus-jdbi</artifactId>
</dependency>
You need to inject AgroalDatasource:
public class JdbiProvider {
@Inject
AgroalDataSource ds;
@Singleton
@Produces
public Jdbi jdbi() {
Jdbi jdbi = Jdbi.create(ds);
jdbi.installPlugin(new SqlObjectPlugin());
return jdbi;
}
}
and you can use it everywhere:
public class UserDAO {
@Inject
Jdbi jdbi;
public Optional<User> findUserById(long id) {
return jdbi.inTransaction(transactionHandle ->
transactionHandle.createQuery("SELECT * FROM users WHERE id=:id")
.bind("id", id)
.mapTo(User.class)
.findFirst());
}
}
Original repo: https://github.com/famartinrh/jdbi-quarkus-extension
Thanks goes to these wonderful people (emoji key):
Tamas 💻 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!