我有一个选择的DAO。我想保留所选数据,以便在返回存储库之前对其进行进一步处理:
@Dao
interface OfferDao {
...
@Query("select * from offer")
fun getOffers(): LiveData<List<Offer>> {
// get a hold of the data
// process it some more
// return offers to caller (repository)
}
这里是Offer
实体:
@Entity(tableName = "offer")
data class Offer(
@PrimaryKey(autoGenerate = false)
var id: Int = 0,
var flightIndex: Int = 0,
var price: Double = 0.0,
var ticketClassIndex: Int = 0,
var ticketClass: String = "",
var supplier: String? = null,
@Ignore
var flight: Flight? = null
)
额外的处理与获取Flight
实体并将其附加到要约有关。在getOffers
函数的主体中,我想通过flightIndex
获取排期并将其附加到要约上,然后再发送回存储库。
答案 0 :(得分:1)
我的建议是尝试类似的东西
@Dao
interface OfferDao {
@Query("select * from offer")
fun getOffers(): LiveData<List<Offer>>
fun getOffersWithFlight(): LiveData<List<Offer>> = getOffers().apply{ forEach { it.flight = GETFLIGHT(it.flightIndex)}}
}
注意:我知道那不是有效的代码,而只是一个示例