在 Google 数据存储中,是否可以获取特定项目的光标?
In Google Datastore, is it possible to get the cursor for a specific item?
可以使用 Datastore.key 为元素生成新键:
const taskKey = datastore.key(['Task', 'sampleTask']);
当运行一个查询时,我们可能会得到一个endCursor可以用来得到下一个结果。
游标是一些 base64 编码的标记,其中包含项目 ID、种类和获取的最后一个元素的键,以及一些未知的二进制数据。
在给定项目键和种类+项目 ID 的情况下,是否可以 way/method 获取 base64 游标值?
不,这不可能。
或者我应该说(尝试)从实体本身获取游标没有多大意义,因为游标仅在获取它的原始查询的上下文中才有意义。来自 Limitations of cursors(强调我的):
Cursors are subject to the following limitations:
- A cursor can be used only by the same application that performed the original query, and only to continue the same query. To use the cursor
in a subsequent retrieval operation, you must reconstitute the
original query exactly, including the same entity kind, ancestor
filter, property filters, and sort orders. It is not possible to
retrieve results using a cursor without setting up the same query from
which it was originally generated.
The cursor's position is defined as the location in the result list
after the last result returned. A cursor is not a relative position in
the list (it's not an offset); it's a marker to which Cloud Datastore
can jump when starting an index scan for results.
如前所述,不可能从键推断游标,因为游标与查询相关联。但是,您可以按键过滤查询。例如。 select * 来自 Task where key > Key(Task, 'sampleTask')
可以使用 Datastore.key 为元素生成新键:
const taskKey = datastore.key(['Task', 'sampleTask']);
当运行一个查询时,我们可能会得到一个endCursor可以用来得到下一个结果。
游标是一些 base64 编码的标记,其中包含项目 ID、种类和获取的最后一个元素的键,以及一些未知的二进制数据。
在给定项目键和种类+项目 ID 的情况下,是否可以 way/method 获取 base64 游标值?
不,这不可能。
或者我应该说(尝试)从实体本身获取游标没有多大意义,因为游标仅在获取它的原始查询的上下文中才有意义。来自 Limitations of cursors(强调我的):
Cursors are subject to the following limitations:
- A cursor can be used only by the same application that performed the original query, and only to continue the same query. To use the cursor in a subsequent retrieval operation, you must reconstitute the original query exactly, including the same entity kind, ancestor filter, property filters, and sort orders. It is not possible to retrieve results using a cursor without setting up the same query from which it was originally generated.
The cursor's position is defined as the location in the result list after the last result returned. A cursor is not a relative position in the list (it's not an offset); it's a marker to which Cloud Datastore can jump when starting an index scan for results.
如前所述,不可能从键推断游标,因为游标与查询相关联。但是,您可以按键过滤查询。例如。 select * 来自 Task where key > Key(Task, 'sampleTask')