Room persistance library. Delete all

前端 未结 8 1127
再見小時候
再見小時候 2020-12-04 11:59

How can I delete all entries on specific table using Room Persistence Library? I need to drop table, but I cannot to find any information how to do this.

Only when d

8条回答
  •  猫巷女王i
    2020-12-04 12:09

    Here is how I have done it in Kotlin.

    1. Inject room db in the activity using DI (Koin).

       private val appDB: AppDB by inject()
      
    2. Then you can simply call clearAllTables()

    private fun clearRoomDB() {
        GlobalScope.launch {
            appDB.clearAllTables()
            preferences.put(PreferenceConstants.IS_UPLOADCATEGORIES_SAVED_TO_DB, false)
            preferences.put(PreferenceConstants.IS_MEMBERHANDBOOK_SAVED_TO_DB, false)
        }
    }
    

提交回复
热议问题