URLSafe datastore key for Google Cloud Datastore Entity

huangapple go评论55阅读模式
英文:

URLSafe datastore key for Google Cloud Datastore Entity

问题

我正在尝试获取Google Cloud Datastore实体的“URL安全键”。根据文档 - https://support.google.com/cloud/answer/6361641?hl=en - Google Cloud Datastore客户端应该有一个执行相同操作的函数。然而,我无法找到它。有人可以帮助吗?我正在使用Python库。谢谢。

英文:

I am trying to get the "URL-safe key" for a Google Cloud Datastore entity. As per the documentation - https://support.google.com/cloud/answer/6361641?hl=en - the Google Cloud Datastore client should have a function to do the same. However, I am not able to locate it. Can someone help with this? I am using the Python lib. Thank you.

答案1

得分: 1

以下是已翻译的内容:

  1. 如果您正在使用Datastore库,您将调用to_legacy_urlsafe方法(参见源代码)。这意味着您要执行myKey.to_legacy_urlsafe()

    要将urlsafe字符串转换回键对象,您需要调用from_legacy_urlsafe方法(参见源代码)。这意味着您要执行google.cloud.datastore.key.Key.from_legacy_urlsafe(<urlsafe_key>)

  2. 如果您正在使用捆绑的ndb API,您需要在键上调用urlsafe方法(参见源代码)。这意味着您要执行myKey.urlsafe()

    要将urlsafe字符串转换回键对象,您需要调用ndb.Key(urlsafe=<urlsafe_key>)(参见源代码

英文:

Assuming you have a key called myKey, following are your options

  1. If you're using the Datastore library, you'll invoke the to_legacy_urlsafe method (see source). This means you do myKey.to_legacy_urlsafe()

    To convert a urlsafe string back to key object, you call from_legacy_urlsafe method (see source). This means you do google.cloud.datastore.key.Key.from_legacy_urlsafe(<urlsafe_key>)

  2. If you're using the bundled ndb API, you invoke the urlsafe method on a key (see source). This means you do myKey.urlsafe()

    To convert a urlsafe string back to key object, you call ndb.Key(urlsafe=<urlsafe_key>) (see source)

huangapple
  • 本文由 发表于 2023年6月8日 06:02:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定