Composition Test 1
This commit is contained in:
parent
b7716b980b
commit
097e5d1f01
@ -6,6 +6,7 @@ import com.example.demo.model.test_db.Tables.MESSAGES
|
|||||||
import com.example.demo.model.test_db.tables.Users.USERS
|
import com.example.demo.model.test_db.tables.Users.USERS
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.asFlow
|
import kotlinx.coroutines.flow.asFlow
|
||||||
|
import org.jooq.Condition
|
||||||
import org.jooq.DSLContext
|
import org.jooq.DSLContext
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.context.annotation.Lazy
|
import org.springframework.context.annotation.Lazy
|
||||||
@ -20,22 +21,22 @@ class UserService(@Autowired @Lazy private val dsl: DSLContext) {
|
|||||||
fun users(): Flux<User> {
|
fun users(): Flux<User> {
|
||||||
return Flux
|
return Flux
|
||||||
.from(dsl
|
.from(dsl
|
||||||
.select()
|
.select()
|
||||||
.from(Tables.USERS))
|
.from(Tables.USERS))
|
||||||
.map {
|
.map {
|
||||||
User(it.get(USERS.ID), it.get(USERS.NAME))
|
User(it.get(USERS.ID), it.get(USERS.NAME))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun users2(): Flow<User> {
|
suspend fun users2(): Flow<User> {
|
||||||
return dsl
|
return dsl
|
||||||
.select()
|
.select()
|
||||||
.from(USERS)
|
.from(USERS)
|
||||||
.fetch()
|
.fetch()
|
||||||
.map { userRecord ->
|
.map { userRecord ->
|
||||||
User(userRecord.get(USERS.ID), userRecord.get(USERS.NAME))
|
User(userRecord.get(USERS.ID), userRecord.get(USERS.NAME))
|
||||||
}
|
}
|
||||||
.asFlow()
|
.asFlow()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getUserMessages(userName: String): Flow<String> = dsl
|
suspend fun getUserMessages(userName: String): Flow<String> = dsl
|
||||||
@ -45,5 +46,15 @@ class UserService(@Autowired @Lazy private val dsl: DSLContext) {
|
|||||||
.map { it.get(MESSAGES.MESSAGE) }
|
.map { it.get(MESSAGES.MESSAGE) }
|
||||||
.asFlow()
|
.asFlow()
|
||||||
|
|
||||||
|
fun test() = dsl
|
||||||
|
.select(Query.messages)
|
||||||
|
.from(MESSAGES)
|
||||||
|
.where(Query.complexClause)
|
||||||
|
.fetch()
|
||||||
|
.asFlow()
|
||||||
|
|
||||||
|
private object Query {
|
||||||
|
val messages = listOf(MESSAGES.MESSAGE)
|
||||||
|
val complexClause: Condition = MESSAGES.MESSAGE.eq("")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user