rxjdbc

rxjdbc

rxjava-jdbc efficient execution, concise code, and functional composition of database calls using JDBC and RxJava Observable.

NOTE: This module depends on jdbc module.

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-rxjava-jdbc</artifactId>
 <version>1.5.1</version>
</dependency>

exports

  • A Database object
  • A Hikari DataSource object

usage

import org.jooby.rx.RxJdbc;
import org.jooby.rx.Rx;
{
  // required
  use(new Rx());
  use(new Jdbc());

  use(new RxJdbc());

  get("/reactive", req ->
    require(Database.class)
      .select("select name from something where id = :id")
      .parameter("id", 1)
      .getAs(String.class)
  );

}

The Rx.rx() mapper converts Observable to deferred instances. More at rx module.

multiple db connections

import org.jooby.rx.RxJdbc;
import org.jooby.rx.Rx;
{
  use(new Jdbc("db.main"));
  use(new RxJdbc("db.main"));

  use(new Jdbc("db.audit"));
  use(new RxJdbc("db.audit"));

  get("/", req ->
    Databse db = require("db.main", Database.class);
    Databse audit = require("db.audit", Database.class);
    // ...
  ).map(Rx.rx());

}

For more details on how to configure the Hikari datasource, please check the jdbc module.