Spring Boot Web Flux with JOOQ for interfacing with DB and Kotlin coroutines to make blocking JDBC calls run asynchronously. Now with rsockets.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package com.example.demo.service
import com.example.demo.model.User import com.example.demo.model.test_db.Tables import com.example.demo.model.test_db.Tables.MESSAGES import com.example.demo.model.test_db.tables.Users.USERS import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import org.jooq.DSLContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Service import reactor.core.publisher.Flux
@Service @Lazy class UserService(@Autowired @Lazy private val dsl: DSLContext) {
fun users(): Flux<User> { return Flux .from(dsl .select() .from(Tables.USERS)) .map { User(it.get(USERS.ID), it.get(USERS.NAME)) } }
suspend fun users2(): Flow<User> { return dsl .select() .from(USERS) .fetch() .map { userRecord -> User(userRecord.get(USERS.ID), userRecord.get(USERS.NAME)) } .asFlow() }
suspend fun getUserMessages(userName: String): Flow<String> = dsl .select(MESSAGES.MESSAGE).from(MESSAGES, USERS) .where(MESSAGES.USER_ID.eq(USERS.ID), USERS.NAME.eq(userName)) .fetch() .map { it.get(MESSAGES.MESSAGE) } .asFlow()
}
|