Skip to content

Instantly share code, notes, and snippets.

@kosmikko
Created March 11, 2011 11:12
Show Gist options
  • Select an option

  • Save kosmikko/865753 to your computer and use it in GitHub Desktop.

Select an option

Save kosmikko/865753 to your computer and use it in GitHub Desktop.
get app engine Query decoded to string
def show_query(query):
"""
Represent a query as a string
Based on http://kupuguy.googlecode.com/svn/trunk/appengine-doctests/showquery.py
"""
from google.appengine.api import datastore
kind = query._model_class.kind()
ancestor = query._Query__ancestor
filters = query._Query__query_sets[0]
orderings = query._Query__orderings
res = ["%s.all()" % kind]
if ancestor is not None:
res.append("ancestor(%r)" % ancestor)
for k in sorted(filters):
res.append("filter(%r, %r)" % (k, filters[k]))
for p, o in orderings:
if o==datastore.Query.DESCENDING:
p = '-'+p
res.append("order(%r)" % p)
return '.'.join(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment