Thanks to all the guys, I got what I need .: D
This can be useful if you have many db models to delete, you can send them to your terminal. And also you can manage the delete list in DB_MODEL_LIST yourself.
Delete DB_1:
python bulkdel.py 10 DB_1
Delete all databases:
python bulkdel.py 11
Here is the bulkdel.py file:
import sys, os URL = 'http://localhost:8080' DB_MODEL_LIST = ['DB_1', 'DB_2', 'DB_3'] # Delete Model if sys.argv[1] == '10' : command = 'curl %s/clear_db?model=%s' % ( URL, sys.argv[2] ) os.system( command ) # Delete All DB Models if sys.argv[1] == '11' : for model in DB_MODEL_LIST : command = 'curl %s/clear_db?model=%s' % ( URL, model ) os.system( command )
And here is a modified version of alexandre fiori code.
from google.appengine.ext import db class DBDelete( webapp.RequestHandler ): def get( self ): self.response.headers['Content-Type'] = 'text/plain' db_model = self.request.get('model') sql = 'SELECT __key__ FROM %s' % db_model try: while True: q = db.GqlQuery( sql ) assert q.count() db.delete( q.fetch(200) ) time.sleep(0.5) except Exception, e: self.response.out.write( repr(e)+'\n' ) pass
And, of course, you must map the link to the model in the file (e.g. main.py in GAE) ;;)
In case some guys like me need this in detail, here is the main.py part:
from google.appengine.ext import webapp import utility
Kjuly Sep 03 '11 at 7:27 2011-09-03 07:27
source share