简体   繁体   中英

How do I delete all Entities in all namespaces in GAE?

Google App Engine allows to administrate the Datastore http://code.google.com/appengine/docs/adminconsole/datastoreadmin.html

but there is no mention about namespaces, except default namespace.

I have alot of namespaces and now I want to delete all entities/namespaces in the Datastore. Is there simple way to do it?

Not sure if this would qualify for simple, but...

You could use the mapper api to create functions that will iterate over entire collections, and you can get all the namespaces used via db.GqlQuery("SELECT * FROM __namespace__")

So assuming you have a function for mapping over all of your entitys like this one called each() . You could run the following in a task or locally with the help of remote_api enabled console to delete everything.

for namespace in each(db.GqlQuery("SELECT * FROM __namespace__")):
    # set the namespace
    namespace_manager.set_namespace( namespace.namespace_name )
    # get all the kinds used in this namespace
    for kind in each(db.GqlQuery("SELECT * FROM __kind__")):
        # get entity 'keys only'
        for key in each(db.GqlQuery("SELECT __key__ FROM %s" % kind.kind_name)):
            db.delete(key)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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