Skip to content

Jdbi provides convenient, idiomatic access to relational data in Java

License

Notifications You must be signed in to change notification settings

quarkiverse/quarkus-jdbi

Repository files navigation

quarkus-jdbi

Build License Central

All Contributors

Jdbi provides convenient, idiomatic access to relational data in Java This quarkus extension makes it possible to use JDBI in native executables.

Example usage

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());
    }
}

Authors

Original repo: https://github.com/famartinrh/jdbi-quarkus-extension

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Tamas

💻 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Jdbi provides convenient, idiomatic access to relational data in Java

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages