使用Room连接查询

4

我有两个房间实体:

@Entity(tableName = LocationsTable.NAME)
data class LocationDto(@PrimaryKey val timestamp: Long,
                   val latitude: Double,
                   val longitude: Double,
                   val altitude: Double)

@Entity(tableName = TripsTable.NAME)
data class TripDto(@PrimaryKey(autoGenerate = true) val _id: Long,
               val startTime: Long,
               val endTime: Long)

现在我正在尝试进行JOIN操作,以获得像这样的对象:

data class TripWithLocationDto(val startTime: Long,
                        val endTime: Long,
                        val locations: List<LocationDto>)

行程实体的起始时间和结束时间之间必须包含locationDtos。查询应该类似于:

SELECT trips_table.start_time, trips_table.end_time FROM trips_table JOIN locations_table WHERE locations_table.timestamp >= trips_table.start_time AND locations_table.timestamp <= trips_table.end_time

所有文章都只描述如何使用外键进行实现。谁知道如何使其工作?

1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接