Jooq reactive fetching using r2dbc driver
When using jOOQ reactively, you should never call any blocking methods, such as ResultQuery.fetchOneInto(Class)
. That method is just a convenience method for ResultQuery.fetchOne()
and then Record.into(Class)
. Nothing keeps you from calling Record.into(Class)
yourself, neither in the blocking world, nor in the non-blocking world.
So, use your usual reactor library methods to map stream contents:
mono.map { r -> r.into(UserCredentialsModel::class.java) }
Or, in a complete example:
return Mono.from {
dsl.select(
USER_CREDENTIALS.ID,
USER_CREDENTIALS.EMAIL,
USER_CREDENTIALS.PHONE,
USER_CREDENTIALS.LOGIN,
USER_CREDENTIALS.PASSWORD)
.from(USER_CREDENTIALS)
.where(USER_CREDENTIALS.ID.eq(id))
.and(USER_CREDENTIALS.IS_ACTIVE.eq(true))
} .map { r -> r.into(UserCredentialsModel::class.java) }
Without testing I would say it should be
return Mono.from(
dsl.select(
USER_CREDENTIALS.ID,
USER_CREDENTIALS.EMAIL,
USER_CREDENTIALS.PHONE,
USER_CREDENTIALS.LOGIN,
USER_CREDENTIALS.PASSWORD)
.from(USER_CREDENTIALS)
.where(USER_CREDENTIALS.ID.eq(id))
.and(USER_CREDENTIALS.IS_ACTIVE.eq(true)));