我在我的应用程序中使用了空间,并想查询一个表,以获取recordingId和markerId的每个唯一组合:
@Entity(tablename = "table")
data class Table(
val recordingId: Int,
val markerId: Int,
...)
TableDao:
@Query("SELECT DISTINCT markerId, recordingId FROM table GROUP BY recordingId")
fun getRecordingWithMarkTyps(): LiveData<List<Pair<Int,Int>>>
但是,我不确定如何将预期的输出映射到查询结果。
按照Official Android documentation的建议,您可以使用正确的实现将结果直接转换为对象。
就您而言,您可以这样声明:
data class Table(
val recordingId: Int,
val markerId: Int,
...)
@Query("SELECT DISTINCT markerId, recordingId FROM table GROUP BY recordingId")
abstract fun getRecordingWithMarkTyps(): List<Table>