queryDSL

queryDSL

SQL abstraction provided by QueryDSL using plain JDBC underneath.

NOTE: This module depends on jdbc module.

exports

  • SQLQueryFactory

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-querydsl</artifactId>
 <version>1.6.6</version>
</dependency>

usage

import org.jooby.querydsl.QueryDSL;
{
  use(new Jdbc());
  use(new QueryDSL());

  get("/my-api", req -> {

    SQLQueryFactory queryFactory = require(SQLQueryFactory.class);
    // Do something with the database
    ...
  });

}

dialects

Dialect is detected automatically and usually you don’t need to do anything. But if the default dialect detector doesn’t work and/or you have a custom dialect:

{
  use(new Jdbc());
  use(new QueryDSL().with(new MyCustomTemplates());
}

multiple databases

import org.jooby.querydsl.QueryDSL;
{
  use(new Jdbc("db.main"));
  use(new QueryDSL("db.main"));

  use(new Jdbc("db.aux"));
  use(new QueryDSL("db.aux"));

  get("/my-api", req -> {
    SQLQueryFactory queryFactory = require("db.main", SQLQueryFactory.class);
    // Do something with the database
  });
}

advanced configuration

This module builds QueryDSL SQLQueryFactories on top of a default Configuration object, a SQLTemplates instance and a javax.sql.DataSource from the jdbc module.

Advanced configuration can be added by invoking the doWith method, adding your own settings to the configuration.

{
  use(new Jdbc());
  use(new QueryDSL().doWith(conf -> {
    conf.set(...);
  });
}

code generation

This module does not provide code generation for DB mapping classes. To learn how to create QueryDSL mapping classes using Maven, please consult the QueryDSL documentation.