-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Manager attaches itself to queries so they can run directly #6
base: master
Are you sure you want to change the base?
Conversation
Hm-- I don't like this solution. It adds state behind the scenes, on the query object, binding the query object to that manager. Queries right now are (a) datastore (/manager) agnostic, and (b) entirely serializable ( If the intent is to reduce the interface: manager = Manager(datastore, model=User)
query = manager.init_query().filter('name', '=', 'John')
results = manager.query(query) perhaps another solution would yield: manager = Manager(datastore, model=User)
query = Query().filter('name', '=', 'John')
results = manager.query(query) This could be done by:
def query(self, query):
mgr_query = query.copy()
mgr_query.key = Key(self.model.key_type).child(query.key)
return self.datastore.query(mgr_query) this would also obviate the need for thoughts, @willembult ? |
aside note: @property
def key(self):
return Key(self.model.key_type) making the above: def query(self, query):
mgr_query = query.copy()
mgr_query.key = self.key.child(query.key)
return self.datastore.query(mgr_query) |
Ah, much better, I agree. |
@willembult would this change code you've written already? (probably...) Also, i'm wary of making mgr = Manager(Person) # Queries:
mgr.query(Query('/')) # /person
mgr.query(Query('/person')) # /person/person
mgr.query(Query('/person/person')) # /person/person/person
mgr.query(Query('/person:foobar')) # /person/person:foobar
mgr.query(Query('foobar')) # /person/foobar
mgr.query(Query(':foobar')) # /person:foobar Not sure if this a problem at all... haven't run into a case where I want to query anyting but the toplevel (all objects of the type) from a manager... (e.g. so far, always |
Ah yes, I hadn't thought of it, but I agree the ambiguity is a problem. With selective prefixing certain queries would become quite counter-intuitive:
As of now, the manager actually refuses to store any objects with keys more than one level deep, so I think always prefixing should be ok. |
It seems unnecessary that we have to feed a query that we got from a Manager back into that Manager to run it. With this change, a Query object retrieved from Manager.init_query() has a reference to the Manager and can be run with a call to perform(), like so:
It can still also be run directly on the datastore, since it merely extends Query.