-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StorIO and pagination #799
Comments
Hello, @Rainer-Lang ! Query.builder()
.table("tweets")
.orderBy("date")
.limit(30, 60) // offset and limit
.build(); If you have some increasing primary key you can insure consistency if beginning of the list will change while pagination: Query.builder()
.table("tweets")
.where("id < ?")
.whereArgs(previousId)
.orderBy("id DESC")
.limit(30)
.build(); Or you can just use |
@nikitin-da Thanks. |
Changes doesn't contain which particular raws were affected, because we can't determinate it for example for raw queries. This is one of possible solutions: observe table and query loaded pages using shared field - minLoadedId. private Observable<Tweet> observeTweets() {
return storio.observeChangesInTable("tables")
.switchMap(changes -> storio.get().listOfObjects(Tweet.class)
.withQuery(
Query.builder()
.table("tweets")
.where("id > ?")
.whereArgs(minLoadedId)
.orderBy("id DESC")
.build()
)
.prepare()
.asRxObservable());
}
private Single<Tweets> loadNextPage() {
return storio.get()
.listOfObjects(Tweet.class)
.withQuery(
Query.builder()
.table("tweets")
.where("id > ?")
.whereArgs(minLoadedId)
.orderBy("id DESC")
.limit(30)
.build()
)
.prepare()
.asRxSingle()
.observeOn(AndroidScheduers.mainThread())
.doOnSuccess(tweets -> minLoadedId = tweets.get(0).id());
} So it allow fast initial load, but if user will load many pages - updates will be slow and all items will be in memory =( |
Has anyone an example how to do pagination with StorIO?
The text was updated successfully, but these errors were encountered: