Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

rxjdbc

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

This module depends on jdbc module and rx module, please read the documentation of jdbc module and rx module before using rx-jdbc.

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-rxjdbc</artifactId>
 <version>1.0.0.CR8</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 RxJdbc());

  get("/reactive", req ->
    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 RxJdbc("db.main"));

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

  get("/", req ->

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

}

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

Happy coding!!!