Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17

Kotlin coroutine support

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

In kotlin, coroutines and suspending functions are a popular way to implement asynchronous, flow style logic. Starting from jOOQ 3.17, the jooq-kotlin-coroutines extension module allows for bridging between the reactive streams API and the coroutine APIs. For this, simply add the following dependencies:

  <!-- Use org.jooq                for the Open Source Edition
           org.jooq.pro            for commercial editions with Java 17 support,
           org.jooq.pro-java-11    for commercial editions with Java 11 support,
           org.jooq.pro-java-8     for commercial editions with Java 8 support,
           org.jooq.trial          for the free trial edition with Java 17 support,
           org.jooq.trial-java-11  for the free trial edition with Java 11 support,
           org.jooq.trial-java-8   for the free trial edition with Java 8 support

       Note: Only the Open Source Edition is hosted on Maven Central.
             Install the others locally using the provided scripts, or access them from here: https://repo.jooq.org -->

And now, you can use jOOQ in a kotlin coroutine style:

suspend fun findActor(id: Long): ActorRecord? {
    return create

        // Turn any reactive streams Publisher<T> into a suspension result using the
        // kotlinx-coroutines-reactive extensions

And wrap your transactional code in the org.jooq.kotlin.coroutines.transactionCoroutine() extension function:

suspend fun insertActorTransaction(): ActorRecord {
    return ctx.transactionCoroutine(::insertActor)

suspend fun insertActor(c: Configuration): ActorRecord = c.dsl()
    .values(201L, "A", "A")
While jOOQ implements the reactive streams API on top of JDBC by default (in a blocking way), we recommend you consider switching to R2DBC driver usage, if you want your coroutines to be truly non-blocking.


Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo