Replies: 1 comment 1 reply
-
My executor code class Result <T> {
var result: T? = null
var exception: Exception? = null
constructor(result: T) {
this.result = result
}
constructor(exception: Exception) {
this.exception = exception
}
constructor() {
}
}
fun <T> exec(block1: (handle:Handle) -> T): Result<T> = jdbi.inTransactionUnchecked {
transactionHandle ->
runBlocking(jdbi.inCoroutineContext()) {
withContext(Dispatchers.IO + jdbi.inCoroutineContext(transactionHandle)) {
val job = async {
var result: Result<T> = Result()
try {
result.result = block1(transactionHandle)
} catch (e: Throwable) {
logger.error("error executing db call", e)
result.exception = Exception(e)
}
result
}
job.await()
}
}
}
I wrote this in an object where I created the Hikari Pool and a singleton Jdbi instance. Is this a correct usage? If I don't catch the exception, the coroutine is crashing when there is a SQL exception and I am not getting any result on the front end. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying a HelloWorld using Kotlin Ktor framework.
Copy pasted some Jetbrains Exposed library code.
I am trying to create a basic execute function that will accept a block, by modeling this class and that can be used similar to the code in this class
Compilation failed with two errors. I had to change the signature as
suspend fun <T> jdbiExec(block: ()-> T) {
to fix it.
what would be a correct
jdbiExec
code that can accept code blocks such asBeta Was this translation helpful? Give feedback.
All reactions