如何使用种类查询在Google数据存储中删除内置种类的名称 [英] How to remove built-in kinds' names in google datastore using kind queries

查看:89
本文介绍了如何使用种类查询在Google数据存储中删除内置种类的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用google cloud datastore种类查询,以获取种类查询

I am trying to use google cloud datastore kind query to get a list of kind names as demoed in the Kind queries,

query = client.query(kind='__kind__')
query.keys_only()

kinds = [entity.key.id_or_name for entity in query.fetch()]

但是代码会生成一些内置的种类名称,例如

but the code generates some built-in kind names, e.g.

['_AE_DatastoreAdmin_Operation', '_GAE_MR_TaskPayload',
 '__Stat_Kind_IsRootEntity__', '__Stat_Kind_NotRootEntity__',
 '__Stat_Kind__', '__Stat_PropertyName_Kind__', 
 '__Stat_PropertyType_Kind__', '__Stat_PropertyType_PropertyName_Kind__',
 '__Stat_PropertyType__', '__Stat_Total__'] 

我想知道如何删除这些内置的种类名称,而仅保留用户创建的种类名称.

I am wondering how to remove these built-in kind names and only retain user created kind names.

推荐答案

这些似乎是在本地开发服务器/仿真器上创建的真实实体-实际上可以在数据存储区查看器中看到它们.例如,当在本地开发服务器上执行数据存储Generate Stats操作时,将创建__Stat_*.

Those appear to be kinds of real entities created on the local development server/emulator - they can actually be seen in the Datastore Viewer. For example the __Stat_* ones are created when the datastore Generate Stats action is performed on the local development server.

这些实体在项目的实时云数据存储中不存在(或存储在其他位置).

These entities do not exist in the project's live cloud datastore (or they are stored elsewhere).

使用针对应用程序实体类型的简单命名规则-不以_字符开头-您可以像这样获得kinds列表:

With a simple naming rule for the application's entity kinds - to not start with the _ character - you could obtain the kinds list like this:

kinds = [entity.key.id_or_name for entity in query.fetch()
             if not entity.key.id_or_name.startswith('_')]

根据kinds的用法,另一种选择-从编码角度看更安全的恕我直言-可能是始终根据明确的预期列表检查种类名称(例如,清除所有kinds实体):

Depending on the kinds use, another option - safer IMHO from coding perspective - might be to always check the kind names against an explicit expected list (for example when wiping out all kinds entities):

kinds = [entity.key.id_or_name for entity in query.fetch()
             if entity.key.id_or_name in known_kinds_list]

这篇关于如何使用种类查询在Google数据存储中删除内置种类的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆