【问题标题】:Room database query that gives out a list with exclusions给出排除列表的房间数据库查询
【发布时间】:2021-01-01 21:20:32
【问题描述】:

我正在尝试查询 Room 以提取元素列表 Entry,但想从 Array<Int> 中排除一些元素。

我的数据库:

@Entity(tableName = "entries", indices = [Index(value = ["id"], unique = true)])

我的对象类将填充我的列表:

data class Entry(
@PrimaryKey(autoGenerate = false)
override var id: Int?,
override val authorId: Int)

我当前的查询以获取所有这些元素:

@Query("SELECT * from entries")
fun entryList() : DataSource.Factory<Int, Entry>

我有一个Array&lt;Int&gt;,它代表一个想要从我的结果中排除的authorId 列表。

之后我可以过滤entryList,但我更愿意进行查询以便检索更小的列表。

问题:我应该使用哪个查询来提取排除在我的Array&lt;Int&gt; 中找到的authorIdentryList

【问题讨论】:

    标签: java android sqlite kotlin android-room


    【解决方案1】:

    你可以试试

    @Query("SELECT * FROM entries WHERE authorId NOT IN (:filterValues)")
    

    并将Array&lt;Int&gt; filterValues 作为参数传递。

    看看有没有效果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      相关资源
      最近更新 更多