Room user configurable order by queries

前端 未结 4 672
误落风尘
误落风尘 2021-01-11 09:00

I am migrating an app to use Room from normal Sqlite and one part that I am having trouble with is that there are several queries that have an orde

4条回答
  •  不思量自难忘°
    2021-01-11 09:54

    In Room 1.1 there is now a RawQuery that can be used that solves this issue

     @Dao
     interface RawDao {
         @RawQuery
         User getUserViaQuery(SupportSQLiteQuery query);
     }
     SimpleSQLiteQuery query = new SimpleSQLiteQuery("SELECT * FROM User WHERE id = ? LIMIT 1",
             new Object[]{userId});
     User user2 = rawDao.getUserViaQuery(query);
    

    https://developer.android.com/reference/android/arch/persistence/room/RawQuery

提交回复
热议问题