Room persistance library. Delete all

前端 未结 8 1120
再見小時候
再見小時候 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条回答
  •  Happy的楠姐
    2020-12-04 12:25

    I had issues with delete all method when using RxJava to execute this task on background. This is how I finally solved it:

    @Dao
    interface UserDao {
        @Query("DELETE FROM User")
        fun deleteAll()
    }
    

    and

    fun deleteAllUsers() {
        return Maybe.fromAction(userDao::deleteAll)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe ({
                d("database rows cleared: $it")
            }, {
                e(it)
            }).addTo(compositeDisposable)
    }
    

提交回复
热议问题