I am checking on implementing the use of cursors for pagination in the Google Cloud Spanner but am unable to find any example which demonstrates the use of Cursor in Cloud Spanner.
My usecase:
Lets suppose I have a service post-sevice and it is accessing the spanner for the posts with query SELECT * from posts where time > X and LIMIT 10
, for one spanner call it will fetch 10 posts and when I again do the spanner call with the same query then it should fetch the next 10 posts but not the previous 10 posts.
// Initial query
results = executeQueryWithLimitAndCursor(null)
// Store the cursor value for later use
storedCursor = results.cursor
// Display the results to the user
// User requests the next page
nextPageResults = executeQueryWithLimitAndCursor(storedCursor)
// Store the new cursor value for later use
storedCursor = nextPageResults.cursor
// Display the next page results to the user
// Repeat the above steps as needed for more pages
Got this link but now that much useful as it doesn't seems for spanner: https://cloud.google.com/datastore/docs/samples/datastore-cursor-paging
For code: I didn't even find a single example where this cursor example is given.
Does the spanner go sdk have support of this cursor or not?
Looking at https://cloud.google.com/datastore/docs/samples/datastore-cursor-paging from datastore, the cursor paging is not supported currently in Cloud Spanner. As suggested earlier using LIMIT and OFFSET could be a workaround for this.