You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But, what If I want to listen to query changes but with limit and offset as results? Is that possible?
Example, I have 1000 messages, but I do show for a user only 100, if a user will scroll, then new messages will be loaded. Also, query automatically updates list if, a new message will be inserted into DB, but with same offset and limit.
Reacted by hangox, Alexander, devjn, Jacob Ferrero, Jac, Issachar, Louis Kirsch and Csaba Toth
So if I understand correctly there is currently no way to limit the amount of objects an observable query returns, other than filtering it with properties?
Say I am only interested in the latest 5 objects, is there any way to get only the latest five objects via a query?
I didn't test this, but it should be possible to use Android Jetpack Paging with the ObjectBoxDataSource.Factory to get a LiveData-instance that supports limited items query, as described here:
If the above ObjectBoxDataSource is not an option, here is how to get started with your own general DataObserver that runs a query with limit and offset:
classLimitOffsetNoteObserver(
privatevalstore:BoxStore,
privatevalobserver:DataObserver<List<Note>>,
privatevaloffset:Long,
privatevallimit:Long
) : DataObserver<Class<Note>> {
overridefunonData(data:Class<Note>) {
val results = store.boxFor(Note::class)
.query(Note_.text.contains("TODO"))
.build()
.find(offset, limit)
observer.onData(results)
}
}
// Keep the subscription while used // to avoid garbage collection of the observer.
subscription = store.subscribe(Note::class.java)
.observer(LimitOffsetNoteObserver(store, observer, offset, limit))
Activity
greenrobot commentedon Dec 7, 2017
Sounds reasonable, keeping this as a feature request.
sapelkinAV commentedon Mar 18, 2018
I really need that feature too) Is it in work?
Queatz commentedon Sep 21, 2018
Looking for this, too. 👍
hendrep commentedon Oct 5, 2018
So if I understand correctly there is currently no way to limit the amount of objects an observable query returns, other than filtering it with properties?
Say I am only interested in the latest 5 objects, is there any way to get only the latest five objects via a query?
TinoGuo commentedon Oct 23, 2018
any update?
ajans commentedon Feb 22, 2021
Is it feasible to use the ObjectBox-support for Jetpack Pagination for this?
Please see my comment on this other closed issue for more details on how to possibly do that.
Queatz commentedon Jul 5, 2021
I am also looking for a way to limit the number of results returned from an observer.
ajans commentedon Jul 8, 2021
I didn't test this, but it should be possible to use Android Jetpack Paging with the ObjectBoxDataSource.Factory to get a LiveData-instance that supports limited items query, as described here:
https://docs.objectbox.io/android/paging-architecture-components
So, you could do something like this (but you would have to add the Android Jetpack Paging dependency for this to work):
(copied from above-mentioned objectbox-docs-page)
Would that solve your problem?
greenrobot-team commentedon Apr 4, 2022
If the above
ObjectBoxDataSourceis not an option, here is how to get started with your own generalDataObserverthat runs a query with limit and offset:greenrobot-team commentedon Sep 21, 2026
Side note: this also affects the RxJava(3) wrapper classes: greenrobot/ObjectBoxRxJava#3