google.appengine.datastore.datastore_query.Batcher

A class that implements the Iterator interface for Batches.

Inherits From: expected_type

Typically constructed by a call to Query.run().

The class hides the "best effort" nature of the datastore by potentially making multiple requests to the datastore and merging the resulting batches. This is accomplished efficiently by prefetching results and mixing both non-blocking and blocking calls to the datastore as needed.

Iterating through batches is almost always more efficient than pulling all results at once as RPC latency is hidden by asynchronously prefetching results.

The batches produce by this class cannot be used to fetch the next batch (through Batch.next_batch()) as before the current batch is returned the request for the next batch has already been sent.

query_options The QueryOptions used to create the first batch.
first_async_batch The first batch produced by Query.run_async(query_options).

Methods

next

View source

Get the next batch. See .next_batch().

next_batch

View source

Get the next batch.

The batch returned by this function cannot be used to fetch the next batch (through Batch.next_batch()). Instead this function will always return None. To retrieve the next batch use .next() or .next_batch(N).

This function may return a batch larger than min_to_fetch, but will never return smaller unless there are no more results.

Special values can be used for min_batch_size: ASYNC_ONLY - Do not perform any synchrounous fetches from the datastore even if the this produces a batch with no results. AT_LEAST_OFFSET - Only pull enough results to satifiy the offset. AT_LEAST_ONE - Pull batches until at least one result is returned.

Args
min_batch_size The minimum number of results to retrieve or one of (ASYNC_ONLY, AT_LEAST_OFFSET, AT_LEAST_ONE)

Returns
The next Batch of results.

__iter__

View source

ASYNC_ONLY None
AT_LEAST_OFFSET 0
AT_LEAST_ONE Instance of google.appengine.api.validation.Validator.expected_type