开发者

How to delete data from Google App Engine?

开发者 https://www.devze.com 2022-12-21 23:54 出处:网络
I created one table in Google App Engine. I 开发者_运维问答stored and retrieved data from Google App Engine.

I created one table in Google App Engine. I 开发者_运维问答stored and retrieved data from Google App Engine. However, I don't know how to delete data from Google App Engine Datastore.


An application can delete an entity from the datastore using a model instance or a Key. The model instance's delete() method deletes the corresponding entity from the datastore. The delete() function takes a Key or list of Keys and deletes the entity (or entities) from the datastore:

q = db.GqlQuery("SELECT * FROM Message WHERE msg_date < :1", earliest_date)
results = q.fetch(10)
for result in results:
    result.delete()

# or...

q = db.GqlQuery("SELECT __key__ FROM Message WHERE msg_date < :1", earliest_date)
results = q.fetch(10)
db.delete(results)

Source and further reading:

  • Google App Engine: Creating, Getting and Deleting Data

If you want to delete all the data in your datastore, you may want to check the following Stack Overflow post:

  • How to delete all datastore in Google App Engine?


You need to find the entity then you need delete it.

So in python it would be

q = db.GqlQuery("SELECT __key__ FROM Message WHERE create_date < :1", earliest_date)
results = q.get()
db.delete(results)

or in Java it would be

pm.deletePersistent(results);

URLS from app engine are

http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Deleting_an_Object http://code.google.com/appengine/docs/python/datastore/creatinggettinganddeletingdata.html#Deleting_an_Entity


In Java

I am assuming that you have an endpoint:

Somethingendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();

And then:

endpoint.remove<ModelName>(long ID); 
0

精彩评论

暂无评论...
验证码 换一张
取 消