会议室用户可通过查询配置订单 [英] Room user configurable order by queries

查看:88
本文介绍了会议室用户可通过查询配置订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移一个应用程序以使用普通的Sqlite中的Room,而我遇到麻烦的部分是,有几个查询的语句可以由用户配置,这意味着它们可以更改它们的方式要查看列表顺序.

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 order by statement that are user configurable, meaning they can change how they want to view the list order.

房间"似乎不允许按语句动态排序,因此我将不得不针对每个语句逐个查询.

What it seems is the Room does not allow for dynamic order by statements so I would have to make individual queries specific for each order by statement.

有没有人找到解决这个问题的更好方法,所以我可以有1条查询语句,其中唯一更改的是order by子句,而我不得不写大约15条额外的基本相同的查询语句?

Has anyone found a better way around this issue so I can have 1 query statement where the only thing that changes is the order by clause vs having to write what in my case would be about 15 extra query statements all basically the same?

推荐答案

在1.1会议室中,现在可以使用RawQuery解决此问题

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

这篇关于会议室用户可通过查询配置订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆