Room persistance library. Delete all

前端 未结 8 1113
再見小時候
再見小時候 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条回答
  • 2020-12-04 12:26

    You can create a DAO method to do this.

    @Dao 
    interface MyDao {
        @Query("DELETE FROM myTableName")
        public void nukeTable();
    }
    
    0 讨论(0)
  • 2020-12-04 12:29

    To make use of the Room without abuse of the @Query annotation first use @Query to select all rows and put them in a list, for example:

    @Query("SELECT * FROM your_class_table")

    List`<`your_class`>` load_all_your_class();
    

    Put his list into the delete annotation, for example:

    @Delete

    void deleteAllOfYourTable(List`<`your_class`>` your_class_list);
    
    0 讨论(0)
提交回复
热议问题