Hey team! im having an issue using Room for a KMM ...
# room
e
Hey team! im having an issue using Room for a KMM project. The issue only happened on iOS. I have a logout method that clear all the database:
Copy code
suspend fun logout(): Flow<Any> {
    return flow {
        userDao.clearAll()
        profileDao.clearAll()
        qrCodeDao.clearAll()
        teamDao.clearFavoriteCategory()
    }
}
this is my Dao for QrCode:
Copy code
@Query("DELETE FROM QRCode")
suspend fun clearAll()
when the user clicks on logout and then login again in the same session (without killing the app) and goes to the Qr code screen will see again the old Qr code
i have this method to check if there is something in the Qr database:
Copy code
@Query("SELECT COUNT(*) FROM QRCode")
suspend fun getQrCodeCount(): Int
and in my repository im doing this:
Copy code
val qrCodeCount = qrCodeDao.getQrCodeCount()
                if (qrCodeCount > 0) {
                    val qrCode = qrCodeDao.fetchQrCode().firstOrNull()
                    emit(qrCode)

                } else {
                    val newQRCode = personService.getQRCode(
                        personId,
                        BuildConfig.X_Api_Key,
                        BuildConfig.X_Api_ClientKey
                    )
                    qrCodeDao.save(newQRCode)
                    emit(newQRCode)
                }
so the issue is that if the user logout and login in the same session will see the old qr. If the user kill the app the issue is not happened since the database was refreshing
b
Assuming the table name is correct, maybe you could trying to do all of the clears in a transaction
Copy code
db.useWriterConnection {
  it.immediateTransaction {
    // dao.clearAll()
  }
}
e
i'll check this