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

1

18

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()

Approver answered 22/9, 2013 at 14:53 Comment(0)
B
40

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)
)
Bunns answered 22/9, 2013 at 15:8 Comment(2)
your query is a list of keys: ndb.delete_multi(query)Lingo
You'll be a little bit better if you use iter instead of fetchSequestrate

© 2022 - 2024 — McMap. All rights reserved.