简体   繁体   English

访问 Datastore 中命名空间的元数据

[英]Access metadata of namespace in Datastore

Is there any way to access metadata of a namespace in Google Cloud Datastore?有什么方法可以访问 Google Cloud Datastore 中命名空间的元数据? Im interested in getting something like a created_at property.我有兴趣获得类似 created_at 属性的东西。

In order to find out all provided properties/attributes for a namespace:为了找出命名空间的所有提供的属性/属性:

ds_client = get_datastore_client(project=PROJECT)

query = ds_client.query(kind="__namespace__")
query.keys_only()
for ns in  query.fetch():
    print(ns)
    print(dir(ns))

Output: Output:

<Entity('__namespace__', 'xxxxx') {}>
['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__dir__',
 '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', 
'__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', 
'__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
 '_meanings', 'clear', 'copy', 'exclude_from_indexes', 'fromkeys', 'get', 'id', 'items',
 'key', 'keys', 'kind', 'pop', 'popitem', 'setdefault', 'update', 'values']

Nothing seems promising似乎没什么希望

Namespaces are implicitly created, so there isn't a backing entity for each namespace.命名空间是隐式创建的,因此每个命名空间都没有支持实体。 Thus there isn't metadata on a namespace.因此命名空间上没有元数据。 Stats entities Stat_Ns_Total are the closest thing to metadata for namespaces.统计实体Stat_Ns_Total是最接近命名空间元数据的东西。

The entities from __namespace__ aren't stored entities and are created for the query itself.来自__namespace__的实体不是存储实体,而是为查询本身创建的。

Each entity in Firestore in Datastore mode has a version field that's available through the EntityResult , but the python client library strips that away from you:( and only provides an updated time and not a created time. Datastore 模式下 Firestore 中的每个实体都有一个版本字段,可通过EntityResult获得,但 python 客户端库将其从您身上剥离:( 并且仅提供更新时间而不是创建时间。

Firestore in Datastore mode provides access to metadata that includes information about entity groups, namespaces, entity kinds, properties, and property representations for each property. Datastore 模式下的 Firestore 提供对元数据的访问,其中包括有关每个属性的实体组、命名空间、实体种类、属性和属性表示的信息。 You can use metadata, for example, to build a custom datastore viewer for your application or for backend administrative functions.例如,您可以使用元数据为您的应用程序或后端管理功能构建自定义数据存储查看器。

You can use a namespace query to find all namespaces used in the application's entities.您可以使用命名空间查询来查找应用程序实体中使用的所有命名空间。 This allows you to perform activities such as administrative functions across multiple namespaces.这允许您跨多个命名空间执行诸如管理功能之类的活动。

Namespace queries return entities of the special kind __ namespace __ whose key name is the name of a namespace.命名空间查询返回特殊类型 __ 命名空间 __ 的实体,其键名是命名空间的名称。 (An exception is the default namespace designated by the empty string "": since the empty string is not a valid key name, this namespace is keyed with the numeric ID 1 instead.) Queries of this type support filtering only for ranges over the special pseudoproperty __ key __, whose value is the entity's key. (一个例外是由空字符串“”指定的默认命名空间:由于空字符串不是有效的键名,因此该命名空间以数字 ID 1 为键。)这种类型的查询仅支持过滤特殊范围内的范围伪属性__key __,其值为实体的key。 The results can be sorted by ascending (but not descending) __ key __ value.结果可以按升序(但不能降序)__key__value 排序。 Because __ namespace __ entities have no properties, both keys-only and non-keys-only queries return the same information.因为 __ 命名空间 __ 实体没有属性,所以仅键和非仅键查询都返回相同的信息。

For reference you can check with the documentation Datastore Metadata and Namespace queries .作为参考,您可以查看文档数据存储元数据命名空间查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM