Kotlin公开事务{}magic

Kotlin公开事务{}magic,kotlin,kotlin-exposed,Kotlin,Kotlin Exposed,我已经接触了一点暴露的SQL框架,但找不到问题的答案:事务{}块从何处获得DB连接 这是一个简单的测试 @Test fun test() { Database.connect({ DriverManager.getConnection("jdbc:postgresql://localhost/foo?user=postgres&password=q1") }) transaction {

我已经接触了一点暴露的SQL框架,但找不到问题的答案:事务{}块从何处获得DB连接

这是一个简单的测试

@Test
    fun test() {
        Database.connect({
            DriverManager.getConnection("jdbc:postgresql://localhost/foo?user=postgres&password=q1")
        })

        transaction {
            connection.isClosed()
        }
    }
事务本身就是一个函数

fun <T> transaction(db: Database? = null, statement: Transaction.() -> T): T

提前谢谢

调用
Database.connect
函数时,您定义默认连接应使用lambda中提供的值获得(在您的情况下,
DriverManager.getConnection
).Hi@Tapac。是的,我明白。但交易呢?它从哪里获得连接?
fun <T> transaction(transactionIsolation: Int, repetitionAttempts: Int, db: Database? = null, statement: Transaction.() -> T): T
transaction{
    ...
}