cursor support in DAL for GAE, thanks Christian
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-06-17 10:12:15) dev
|
Version 2.00.0 (2012-06-17 23:09:12) dev
|
||||||
|
|||||||
+17
-2
@@ -4161,7 +4161,11 @@ class GoogleDatastoreAdapter(NoSQLAdapter):
|
|||||||
query_projection = [p for p in projection if \
|
query_projection = [p for p in projection if \
|
||||||
p != self.db[tablename]._id.name] if projection \
|
p != self.db[tablename]._id.name] if projection \
|
||||||
else None
|
else None
|
||||||
items = gae.Query(tableobj, projection=query_projection)
|
|
||||||
|
cursor = None
|
||||||
|
if isinstance(attributes.get('reusecursor'), str):
|
||||||
|
cursor = attributes.get('reusecursor')
|
||||||
|
items = gae.Query(tableobj, projection=query_projection, cursor=cursor)
|
||||||
|
|
||||||
for filter in filters:
|
for filter in filters:
|
||||||
if attributes.get('projection') == True and \
|
if attributes.get('projection') == True and \
|
||||||
@@ -4211,7 +4215,12 @@ class GoogleDatastoreAdapter(NoSQLAdapter):
|
|||||||
if attributes.get('limitby', None):
|
if attributes.get('limitby', None):
|
||||||
(lmin, lmax) = attributes['limitby']
|
(lmin, lmax) = attributes['limitby']
|
||||||
(limit, offset) = (lmax - lmin, lmin)
|
(limit, offset) = (lmax - lmin, lmin)
|
||||||
items = items.fetch(limit,offset=offset)
|
rows = items.fetch(limit,offset=offset)
|
||||||
|
#cursor is only useful if there was a limit and we didn't return
|
||||||
|
# all results
|
||||||
|
if attributes.get('reusecursor'):
|
||||||
|
self.db['_lastcursor'] = items.cursor()
|
||||||
|
items = rows
|
||||||
return (items, tablename, projection or self.db[tablename].fields)
|
return (items, tablename, projection or self.db[tablename].fields)
|
||||||
|
|
||||||
def select(self,query,fields,attributes):
|
def select(self,query,fields,attributes):
|
||||||
@@ -4225,6 +4234,12 @@ class GoogleDatastoreAdapter(NoSQLAdapter):
|
|||||||
what is accepted imposed by GAE: each field must be indexed,
|
what is accepted imposed by GAE: each field must be indexed,
|
||||||
projection queries cannot contain blob or text fields, and you
|
projection queries cannot contain blob or text fields, and you
|
||||||
cannot use == and also select that same field. see https://developers.google.com/appengine/docs/python/datastore/queries#Query_Projection
|
cannot use == and also select that same field. see https://developers.google.com/appengine/docs/python/datastore/queries#Query_Projection
|
||||||
|
- optional attribute 'reusecursor' allows use of cursor with queries
|
||||||
|
that have the limitby attribute. Set the attribute to True for the
|
||||||
|
first query, set it to the value of db['_lastcursor'] to continue
|
||||||
|
a previous query. The user must save the cursor value between
|
||||||
|
requests, and the filters must be identical. It is up to the user
|
||||||
|
to follow google's limitations: https://developers.google.com/appengine/docs/python/datastore/queries#Query_Cursors
|
||||||
"""
|
"""
|
||||||
|
|
||||||
(items, tablename, fields) = self.select_raw(query,fields,attributes)
|
(items, tablename, fields) = self.select_raw(query,fields,attributes)
|
||||||
|
|||||||
Reference in New Issue
Block a user