google app engine - GAE & datastore - filter and delete entities with python -


i'm trying delete datastore table entities have type field value equals "test".

actually table structure this:

table test

id    |    type    |    value     --------------------------------- 1     |   test     |    aksjdh 2     |   foo      |    wer 3     |   test     |    gg 4     |   test     |    werqwer 5     |   bar      |    akvcvcxjdh 

i'm able delete entities piece of python code, called via url request:

import cgi import datetime import urllib import webapp2 google.appengine.ext import db  class test(db.model):     id = db.stringproperty()     type = db.stringproperty()     value = db.stringproperty()  class testhandler(webapp2.requesthandler):     def get(self):         ...         db.delete(test.all())  app = webapp2.wsgiapplication([     ('/deletetest', testhandler) ], debug=true) 

what i'd know is: in previous code, delete test's entities, i've used method all() of test's class, have use same logic delete subset of entities, based on type value? should store entire list in test object , proceed further filtering?

in other words, can

db.delete(db.gqlquery("select * test type = :1", "test"))  

or better doing like

#i don't know if exists, it's example testlist = test.all() db.delete(testlist.filter("type", "test")) 

note in 2nd example, i've firstly instantiated sort of test object, , deleted entities starting object.

i hope mean, thing tricky in mind , i'm not sure explained well..

thanks in advance, best regards

your gql ok, though should keys query more efficient.

db.delete(db.gqlquery("select __key__ test type = :1", "test"))

using filter should be

testlist = test.all(keys_only=true) db.delete(testlist.filter("type = ", "test")) 

you find large numbers of records in production approach won't scale. trying in web request many thousands of entities more end deadlineexceedederror.

if run delete in task 10 minutes complete request, if large numbers won't work.

if trying clear dev datastore use command line clearing datastore on dev server startup.

some other things consider.

if starting out, switch ndb. should protect such web method with sort of authentication/access control. consider learning rest , methodology. requests mutate shouldn't done get, use delete or post. - things consider.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -