google.appengine.api.datastore.MultiQuery

Class representing a query which requires multiple datastore queries.

Inherits From: Query, expected_type

This class is actually a subclass of datastore.Query as it is intended to act like a normal Query object (supporting the same interface).

Does not support keys only queries, since it needs whole entities in order to merge sort them. (That's not true if there are no sort orders, or if the sort order is on key, but allowing keys only queries in those cases, but not in others, would be confusing.)

namespace string, the namespace to query.
kind string, the kind of entities to query, or None.
filters dict, initial set of filters.
keys_only boolean, if keys should be returned instead of entities.
projection iterable of property names to project.
distinct boolean, if projection should be distinct.
compile boolean, if the query should generate cursors.
cursor datastore_query.Cursor, the start cursor to use.
end_cursor datastore_query.Cursor, the end cursor to use.
_namespace deprecated, use namespace instead.

Child Classes

class SortOrderEntity

Methods

Ancestor

View source

Sets an ancestor for this query.

This restricts the query to only return result entities that are descended from a given entity. In other words, all of the results will have the ancestor as their parent, or parent's parent, or etc.

Raises BadArgumentError or BadKeyError if parent is not an existing Entity or Key in the datastore.

Args

the key must be complete

ancestor Entity or Key

Returns

this query

Query

Count

View source

Return the number of matched entities for this query.

Will return the de-duplicated count of results. Will call the more efficient Get() function if a limit is given.

Args
limit maximum number of entries to count (for any result > limit, return limit).
config Optional Configuration to use for this request.

Returns
count of the number of entries returned.

Get

View source

Deprecated, use list(Run(...)) instead.

Args
limit int or long representing the maximum number of entities to return.
offset int or long representing the number of entities to skip
kwargs Any keyword arguments accepted by datastore_query.QueryOptions().

Returns
A list of entities with at most "limit" entries (less if the query completes before reading limit values).

GetBatcher

View source

Runs this query and returns a datastore_query.Batcher.

This is not intended to be used by application developers. Use Get() instead!

Args
config Optional Configuration to use for this request.

Returns

an iterator that provides access to the query results

Iterator

GetCompiledCursor

View source

Get the cursor from the last run of this query.

The source of this cursor varies depending on what the last call was:

  • Run: A cursor that points immediately after the last result pulled off the returned iterator.
  • Get: A cursor that points immediately after the last result in the returned list.
  • Count: A cursor that points immediately after the last result counted.

Returns
A datastore_query.Cursor object that can be used in subsequent query requests.

Raises
AssertionError The query has not yet been run or cannot be compiled.

GetCompiledQuery

View source

Internal only, do not use.

GetCursor

View source

Get the cursor from the last run of this query.

The source of this cursor varies depending on what the last call was:

  • Run: A cursor that points immediately after the last result pulled off the returned iterator.
  • Get: A cursor that points immediately after the last result in the returned list.
  • Count: A cursor that points immediately after the last result counted.

Returns
A datastore_query.Cursor object that can be used in subsequent query requests.

Raises
AssertionError The query has not yet been run or cannot be compiled.

GetDistinct

View source

Returns True if the current instance is distinct.

Returns
A boolean indicating if the distinct flag is set.

GetFilterPredicate

View source

Returns a datastore_query.FilterPredicate for the current instance.

Returns
datastore_query.FilterPredicate or None if no filters are set on the current Query.

GetIndexList

View source

Get the index list from the last run of this query.

Returns
A list of indexes used by the last run of this query.

Raises
AssertionError The query has not yet been run.

GetOrder

View source

Gets a datastore_query.Order for the current instance.

Returns
datastore_query.Order or None if there are no sort orders set on the current Query.

GetQuery

View source

Returns a datastore_query.Query for the current instance.

GetQueryOptions

View source

Returns a datastore_query.QueryOptions for the current instance.

Hint

View source

Sets a hint for how this query should run.

The query hint gives us information about how best to execute your query. Currently, we can only do one index scan, so the query hint should be used to indicates which index we should scan against.

Use FILTER_FIRST if your first filter will only match a few results. In this case, it will be most efficient to scan against the index for this property, load the results into memory, and apply the remaining filters and sort orders there.

Similarly, use ANCESTOR_FIRST if the query's ancestor only has a few descendants. In this case, it will be most efficient to scan all entities below the ancestor and load them into memory first.

Use ORDER_FIRST if the query has a sort order and the result set is large or you only plan to fetch the first few results. In that case, we shouldn't try to load all of the results into memory; instead, we should scan the index for this property, which is in sorted order.

Note that hints are currently ignored in the v3 datastore!

Arg
one of datastore.Query.[ORDER_FIRST, ANCESTOR_FIRST, FILTER_FIRST]

Returns

this query

Query

IsKeysOnly

View source

Returns True if this query is keys only, False otherwise.

Order

View source

Specify how the query results should be sorted.

Result entities will be sorted by the first property argument, then by the second, and so on. For example, this:

> query = Query('Person') > query.Order('bday', ('age', Query.DESCENDING))

sorts everyone in order of their birthday, starting with January 1. People with the same birthday are sorted by age, oldest to youngest.

The direction for each sort property may be provided; if omitted, it defaults to ascending.

Order() may be called multiple times. Each call resets the sort order from scratch.

If an inequality filter exists in this Query it must be the first property passed to Order. Any number of sort orders may be used after the inequality filter property. Without inequality filters, any number of filters with different orders may be specified.

Entities with multiple values for an order property are sorted by their lowest value.

Note that a sort order implies an existence filter! In other words, Entities without the sort order property are filtered out, and not included in the query results.

If the sort order property has different types in different entities - ie, if bob['id'] is an int and fred['id'] is a string - the entities will be grouped first by the property type, then sorted within type. No attempt is made to compare property values across types.

Raises BadArgumentError if any argument is of the wrong format.

Args

the properties to sort by, in sort order. each argument may be either a

string or (string, direction) 2-tuple.

Returns

this query

Query

Run

View source

Return an iterable output with all results in order.

Merge sort the results. First create a list of iterators, then walk though them and yield results in order.

Args
kwargs Any keyword arguments accepted by datastore_query.QueryOptions().

Returns
An iterator for the result set.

clear

D.clear() -> None. Remove all items from D.

copy

View source

The copy method is not supported.

fromkeys

Create a new dictionary with keys from iterable and values set to value.

get

Return the value for key if key is in the dictionary, else default.

items

D.items() -> a set-like object providing a view on D's items

keys

D.keys() -> a set-like object providing a view on D's keys

pop

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault

View source

If the filter exists, returns its value. Otherwise sets it to value.

If the property name is the empty string or not a string, raises BadPropertyError. If the value is not a supported type, raises BadValueError.

update

View source

Updates this query's filters from the ones in other.

If any filter string is invalid, raises BadFilterError. If any value is not a supported type, raises BadValueError.

values

D.values() -> an object providing a view on D's values

__contains__

True if the dictionary has the specified key, else False.

__eq__

Return self==value.

__ge__

Return self>=value.

__getitem__

x.getitem(y) <==> x[y]

__gt__

Return self>value.

__iter__

View source

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__ne__

Return self!=value.

__or__

Return self|value.

__ror__

Return value|self.

ANCESTOR_FIRST 2
ASCENDING 1
DESCENDING 2
FILTER_FIRST 3
FILTER_REGEX Instance of re.Pattern
INEQUALITY_OPERATORS

{
 '<',
 '<=',
 '>',
 '>='
}

OPERATORS

{
 '<': 1,
 '<=': 2,
 '=': 5,
 '==': 5,
 '>': 3,
 '>=': 4
}

ORDER_FIRST 1
UPPERBOUND_INEQUALITY_OPERATORS

{
 '<',
 '<='
}