在最近的Room版本2.1.0中,Android团队引入了DatabaseView:https://developer.android.com/training/data-storage/room/creating-views
我们如何选择Databaseview作为DataSource.Factory以便在PagedList.BoundaryCallback中使用它。
例如,我们有数据库视图:
@DatabaseView("SELECT user.id, user.name, user.departmentId," +
"department.name AS departmentName FROM user " +
"INNER JOIN department ON user.departmentId = department.id")
data class UserDetail(
val id: Long,
val name: String?,
val departmentId: Long,
val departmentName: String?
)
但是当我查询这样的Dao类中获取UserDetail时
@Query("SELECT * FROM UserDetail WHERE id= :id")
fun getUserDetail(id: String) : DataSource.Factory<Int, UserDetail>
我看到它将返回当前数据库中的所有项目,尽管我将页面大小配置为仅20个项目。我们可以使用databaseview进行分页吗?