我想将jOOQ与Kotlin Coroutines一起使用,但我找不到文档或示例代码来了解如何正确使用它.
我想 Select 与我的查询匹配的所有行,并将它们映射到我的POJO中.
我试过各种组合.fetchAsync
听起来正确,但映射后返回类型不正确
Incorrect return type of 100
open suspend fun findAll(): Flow<Model> {
return ctx.select()
.from(table)
.fetchAsync()
.await()
.into(modelClass) // Into is blocking
}
如果我想阻止它,我可以使用:
return ctx.select()
.from(table)
.fetchInto(modelClass)
但没有百分百的方法.
此外,如果我想要执行一个EXISTS查询,我可以看到它是如何通过阻塞来完成的,但不是异步的.
例如
ctx.fetchExists(dslContext.selectFrom(table).where(YOUR_TABLE.ID.eq(id))
如何使用带有Kotlin Coroutines的jOOQ执行SELECT ALL AND EXISTS查询?
Update个 我可以用熔剂来解决这个问题.
Flux.from(ctx.select().from(table))
.map { record -> record.into(modelClass) }
.asFlow()
Exists query update个
这会成功运行,但不会直接运行EXISTS查询.
val result = ctx.selectFrom(table)
.where(USER_MODEL.EMAIL.eq(email))
.awaitFirstOrNull()
return result != null
我试着这样写查询,但它抛出了一个Cannot execute query. No JDBC Connection configured
异常:
select(
exists(
ctx.selectFrom(table)
.where(USER_MODEL.EMAIL.eq(email))
)
).awaitFirst().into(Boolean::class.java)