I would like to get a list of KINDS
from my google app engine datastore using queries (GQL
maybe?). For example the way one would simply show tables
of a database.
I have looked at a similar question (How to list kinds in datastore?), however it does not solve my problem as it is python specific.
I am currently using a GDS library in PHP (https://github.com/tomwalder/php-gds) that helps me fetch data from GDS if I know the Entity name using "SELECT * FROM Kind"
GQL query.
I am currently in a situation where I may not know the name of the Entity KIND which I need to fetch data from hence the need to get the list of Entity KINDS which I can then look through and confirm if the entity exists, then run my select query.
Any pointers would be greatly appreciated.
You can query them Using the metadata objects of ndb.
https://cloud.google.com/appengine/docs/python/ndb/metadata#get_kinds
Here's an alternate approach based on GQL... This returns a list of the Kinds available:
SELECT * FROM __kind__
In theory, you can then obtain the schema for this object by listing the associated properties for a given Kind (e.g., Person):
SELECT * FROM __property__
WHERE __key__ HAS ANCESTOR KEY(__kind__, 'Person')
If you are using Google's library to issue these queries, then you will have to set the AllowLiterals = true
property in your request to avoid getting an exception with an error detail saying Disallowed literal: KEY
.
Also, since the property_representation
values are overloaded for things like Dates vs Integers, then you can only use the type data as a guess of the underlying type, possibly using conventions. As you cursor through the data, you could update the type information. It's curious that there isn't a better way since Google's Datastore UI provides type information when you create a new instance of an Entity.