File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
krescent-exposed/src/main/kotlin/dev/helight/krescent/exposed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,19 @@ import kotlinx.coroutines.coroutineScope
66import kotlinx.coroutines.runBlocking
77import org.jetbrains.exposed.sql.Database
88import org.jetbrains.exposed.sql.Transaction
9+ import org.jetbrains.exposed.sql.transactions.TransactionManager
910import org.jetbrains.exposed.sql.transactions.transaction
1011
11- internal suspend fun <T > jdbcSuspendTransaction (database : Database , statement : suspend Transaction .() -> T ): T =
12+ internal suspend fun <T > jdbcSuspendTransaction (
13+ database : Database ,
14+ reuseTransaction : Boolean = false,
15+ statement : suspend Transaction .() -> T ,
16+ ): T =
1217 coroutineScope {
18+ if (reuseTransaction) TransactionManager .currentOrNull()
19+ ?.takeIf { it.db == database }
20+ ?.let { return @coroutineScope statement.invoke(it) }
21+
1322 async(Dispatchers .IO ) {
1423 transaction(database) {
1524 runBlocking {
You can’t perform that action at this time.
0 commit comments