1. Sql Client

A reactive SQL Client. Supported databases:

  • MySQL

These modules require a Vertx instance available in the service registry.

1.1. MySQL

1) Add the dependency:

Maven
Gradle
<!-- Vertx Module-->
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-vertx</artifactId>
  <version>4.0.11</version>
</dependency>

<!-- MySQL Client-->
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-vertx-mysql-client</artifactId>
  <version>4.0.11</version>
</dependency>

2) Define connection string or key/value pairs details:

application.conf
db = MySQL//dbuser:secretpassword@localhost:{{port}}/mydb
application.conf
db.host = localhost
db.port = {{port}}
db.database = mydb
db.user = dbuser
db.password = secretpassword

3) Install

Java
Kotlin
import io.jooby.vertx.VertxModule;
import io.jooby.vertx.VertxMySQLModule;
import static io.jooby.vertx.VertxHandler.vertx;

{
  install(new VertxModule());                                          (1)

  install(new VertxMySQLModule());                                     (2)

  use(vertx());                                                        (3)

  get("/{id}", ctx -> {
    var db = require(SqlClient.class);                                 (4)
    return db.preparedQuery("SELECT id, name from World where id=$1")  (5)
        .execute(Tuple.of(ctx.path("id").longValue()))
        .map(result -> {
          var row = result.iterator().next();
          return new World(row.getInteger(0), row.getInteger(1));
        });
  });
}
1 Install Vertx
2 Install Sql Client: {{sqlClient}
3 Install vertx handler. Render future, promise and buffer
4 Get SQL client instance
5 Run a database query

To use the client version of the driver:

Client
{
  ...
  install(new VertxMySQLModule(MySQLBuilder::client));
  ...
}