room 查询语句记录

59 阅读1分钟
//插入
@Insert
fun insertCategory(item:Category):Long
//插入
@Insert
fun insertCategorys(item:List<Category>):List<Long>
//查询
@Query("select * from Category")
fun queryCategory():List<Category>
//条件查询
@Query("select * from Category where type = (:type)")
fun queryCategoryByType(type:Int):List<Category>
//模糊查询
@Query("select * from Category where title like '%' ||:type ||'%'")
fun queryCategoryByTagStr(type:String):List<Category>
@Dao
interface DailyRecordDao {
    //批量插入
    @Insert
    fun insertRecords(item:List<RecordItemInfo>):List<Long>
    //单个插入
    @Insert
    fun insertRecord(item:RecordItemInfo):Long
    //普通查询
    @Transaction
    @Query("select * from RecordItemInfo")
    fun queryRecord():List<RecordAndCategory>

    //Date 查询
    @Transaction(这个注解是因为有关联表)
    @Query("select * from RecordItemInfo where date = (:date)")
    fun queryRecordByDate(date:Date):List<RecordAndCategory>

    //区间查询
    @Transaction
    @Query("select * from RecordItemInfo where date > (:startMonth) and date < (:endMonth)")
    fun queryRecordByMonth(startMonth:Date,endMonth:Date):List<RecordAndCategory>
    //集合查询
    @Transaction
    @Query("select * from RecordItemInfo where categoryId in (:categoryIds)")
    fun queryRecordByCategoryIds(categoryIds:List<Int>):List<RecordAndCategory>
    //比较查询
    @Transaction
    @Query("select * from RecordItemInfo where money >= (:money)")
    fun queryRecordByMoney(money:Double):List<RecordAndCategory>
}