我正在检查在 Google Cloud Spanner 中使用光标进行分页的情况,但找不到任何演示在 Cloud Spanner 中使用光标的示例。
我的用例: 假设我有一项售后服务,它正在使用查询
SELECT * from posts where time > X and LIMIT 10
访问帖子的扳手,对于一次扳手调用,它将获取 10 个帖子,当我再次使用相同的查询进行扳手调用时,它应该获取接下来的 10 个帖子,但不是前 10 个帖子。
// 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
得到了这个链接,但现在非常有用,因为它似乎不适用于扳手:https://cloud.google.com/datastore/docs/samples/datastore-cursor-paging
对于代码:我什至没有找到给出此光标示例的单个示例。
spanner go sdk是否支持该光标?
从数据存储区查看 https://cloud.google.com/datastore/docs/samples/datastore-cursor-paging,Cloud Spanner 目前不支持光标分页。 正如之前所建议的,使用 LIMIT 和 OFFSET 可能是解决此问题的方法。