Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all entities for NDB Model in Google App Engine for python?

I have a ndb model class:

class Game(ndb.Model):
    gameID = ndb.IntegerProperty()
    gameName = ndb.StringProperty()

Is there any way to quickly just delete all entities thats stored in the database for this class? Something like Game.deletAll()

like image 869
bogen Avatar asked Sep 22 '13 14:09

bogen


People also ask

How do I delete a entity from Datastore?

You can delete from multiple data store entities in one transaction by creating an array of type EntityDataIdentifiers. All entities defined in the array must be of the same data store.

What is NDB Python?

The Google Datastore NDB Client Library allows App Engine Python apps to connect to Datastore. The NDB client library builds on the older DB Datastore library adding the following data store features: The StructuredProperty class, which allows entities to have nested structure.

How do I update entity in Datastore?

To update an existing entity, modify the attributes of the Entity object, then pass it to the DatastoreService. put() method. The object data overwrites the existing entity. The entire object is sent to Datastore with every call to put() .

What are properties of entities?

An entity has one or more named properties, each of which can have one or more values. Entities of the same kind do not need to have the same properties, and an entity's values for a given property do not all need to be of the same data type.


1 Answers

No, but you could easily do this with something like:

from google.appengine.ext import ndb

ndb.delete_multi(
    Game.query().fetch(keys_only=True)
)
like image 88
Jesse Avatar answered Oct 12 '22 00:10

Jesse