如何使用来自不同 DAO 的函数和协程与 Room 进行数据库事务?

How to make a database transaction with Room using functions from differents DAOs and using coroutines?

我想使用协程使用来自不同 Daos 的函数与 Room 进行数据库事务。

如果我使用 @Transaction 注释,我只能使用同一个 DAO 中的函数。如果我使用 Room 数据库功能 runInTransaction 我不能使用协程。

有办法实现吗?

withTransaction() 有一个暂停扩展功能。看看这个:

https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/room/ktx/src/main/java/androidx/room/RoomDatabase.kt