App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Public Member Functions | List of all members
google.appengine.ext.ndb.query.QueryIterator Class Reference
Inheritance diagram for google.appengine.ext.ndb.query.QueryIterator:

Public Member Functions

def __init__
 
def cursor_before
 
def cursor_after
 
def index_list
 
def __iter__
 
def probably_has_next
 
def has_next
 
def has_next_async
 
def next
 

Detailed Description

This iterator works both for synchronous and async callers!

For synchronous callers, just use:

  for entity in Account.query():
    <use entity>

Async callers use this idiom:

  it = iter(Account.query())
  while (yield it.has_next_async()):
    entity = it.next()
    <use entity>

You can also use q.iter([options]) instead of iter(q); this allows
passing query options such as keys_only or produce_cursors.

When keys_only is set, it.next() returns a key instead of an entity.

When produce_cursors is set, the methods it.cursor_before() and
it.cursor_after() return Cursor objects corresponding to the query
position just before and after the item returned by it.next().
Before it.next() is called for the first time, both raise an
exception.  Once the loop is exhausted, both return the cursor after
the last item returned.  Calling it.has_next() does not affect the
cursors; you must call it.next() before the cursors move.  Note that
sometimes requesting a cursor requires a datastore roundtrip (but
not if you happen to request a cursor corresponding to a batch
boundary).  If produce_cursors is not set, both methods always raise
an exception.

Note that queries requiring in-memory merging of multiple queries
(i.e. queries using the IN, != or OR operators) do not support query
options.

Constructor & Destructor Documentation

def google.appengine.ext.ndb.query.QueryIterator.__init__ (   self,
  query,
  q_options 
)
Constructor.  Takes a Query and query options.

This is normally called by Query.iter() or Query.__iter__().

Member Function Documentation

def google.appengine.ext.ndb.query.QueryIterator.__iter__ (   self)
Iterator protocol: get the iterator for this iterator, i.e. self.
def google.appengine.ext.ndb.query.QueryIterator.cursor_after (   self)
Return the cursor after the current item.

You must pass a QueryOptions object with produce_cursors=True
for this to work.

If there is no cursor or no current item, raise BadArgumentError.
Before next() has returned there is no cursor.    Once the loop is
exhausted, this returns the cursor after the last item.
def google.appengine.ext.ndb.query.QueryIterator.cursor_before (   self)
Return the cursor before the current item.

You must pass a QueryOptions object with produce_cursors=True
for this to work.

If there is no cursor or no current item, raise BadArgumentError.
Before next() has returned there is no cursor.  Once the loop is
exhausted, this returns the cursor after the last item.
def google.appengine.ext.ndb.query.QueryIterator.has_next (   self)
Return whether a next item is available.

See the module docstring for the usage pattern.
def google.appengine.ext.ndb.query.QueryIterator.has_next_async (   self)
Return a Future whose result will say whether a next item is available.

See the module docstring for the usage pattern.
def google.appengine.ext.ndb.query.QueryIterator.index_list (   self)
Return the list of indexes used for this query.

This returns a list of index representations, where an index
representation is the same as what is returned by get_indexes().

Before the first result, the information is unavailable, and then
None is returned.  This is not the same as an empty list -- the
empty list means that no index was used to execute the query.  (In
the dev_appserver, an empty list may also mean that only built-in
indexes were used; metadata queries also return an empty list
here.)

Proper use is as follows:
  q = <modelclass>.query(<filters>)
  i = q.iter()
  try:
i.next()
  except Stopiteration:
pass
  indexes = i.index_list()
  assert isinstance(indexes, list)

Notes:
- Forcing produce_cursors=False makes this always return None.
- This always returns None for a multi-query.
def google.appengine.ext.ndb.query.QueryIterator.next (   self)
Iterator protocol: get next item or raise StopIteration.
def google.appengine.ext.ndb.query.QueryIterator.probably_has_next (   self)
Return whether a next item is (probably) available.

This is not quite the same as has_next(), because when
produce_cursors is set, some shortcuts are possible.  However, in
some cases (e.g. when the query has a post_filter) we can get a
false positive (returns True but next() will raise StopIteration).
There are no false negatives, if Batch.more_results doesn't lie.

The documentation for this class was generated from the following file: