3

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.

Deniss T.
  • 2,526
  • 9
  • 21
user246160
  • 1,389
  • 7
  • 18
  • 33

3 Answers3

4

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:

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

Community
  • 1
  • 1
Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
1

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

AutomatedTester
  • 22,188
  • 7
  • 49
  • 62
0

In Java

I am assuming that you have an endpoint:

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

And then:

endpoint.remove<ModelName>(long ID); 
eknbrk
  • 187
  • 1
  • 1
  • 16