當前位置: 首頁>>代碼示例>>Python>>正文


Python datastore_query.QueryOptions方法代碼示例

本文整理匯總了Python中google.appengine.datastore.datastore_query.QueryOptions方法的典型用法代碼示例。如果您正苦於以下問題:Python datastore_query.QueryOptions方法的具體用法?Python datastore_query.QueryOptions怎麽用?Python datastore_query.QueryOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.datastore.datastore_query的用法示例。


在下文中一共展示了datastore_query.QueryOptions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __iter__

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def __iter__(self):
    query = self._key_range.make_ascending_datastore_query(
        self._query_spec.entity_kind, filters=self._query_spec.filters)
    # get a connection without adapter.
    connection = datastore_rpc.Connection()
    query_options = datastore_query.QueryOptions(
        batch_size=self._query_spec.batch_size,
        start_cursor=self._cursor,
        produce_cursors=True)

    # Transform datastore.Query:
    # datastore.Query -> datastore_query.Query -> datastore_query.Batcher ->
    # datastore_query.ResultsIterator
    self._query = datastore_query.ResultsIterator(
        query.GetQuery().run(connection, query_options))
    for entity_proto in self._query:
      yield entity_proto 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:19,代碼來源:datastore_range_iterators.py

示例2: Get

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def Get(self, limit, offset=0, **kwargs):
    """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
      [Entity, ...]
    """
    if limit is None:
      kwargs.setdefault('batch_size', _MAX_INT_32)

    return list(self.Run(limit=limit, offset=offset, **kwargs)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:18,代碼來源:datastore.py

示例3: __GetProjectionOverride

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def __GetProjectionOverride(self,  config):
    """Returns a tuple of (original projection, projeciton override).

    If projection is None, there is no projection. If override is None,
    projection is sufficent for this query.
    """
    projection = datastore_query.QueryOptions.projection(config)
    if  projection is None:
      projection = self.__projection
    else:
      projection = projection

    if not projection:
      return None, None



    override = set()
    for prop, _ in self.__orderings:
      if prop not in projection:
        override.add(prop)
    if not override:
      return projection, None

    return projection, projection + tuple(override) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:27,代碼來源:datastore.py

示例4: run

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def run(self, **kwargs):
    """Iterator for this query.

    If you know the number of results you need, use run(limit=...) instead,
    or use a GQL query with a LIMIT clause. It's more efficient. If you want
    all results use run(batch_size=<large number>).

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

    Returns:
      Iterator for this query.
    """
    raw_query = self._get_query()
    iterator = raw_query.Run(**kwargs)
    self._last_raw_query = raw_query

    keys_only = kwargs.get('keys_only')
    if keys_only is None:
      keys_only = self.is_keys_only()

    if keys_only:
      return iterator
    else:
      return _QueryIterator(self._model_class, iter(iterator)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:27,代碼來源:__init__.py

示例5: get

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def get(self, **kwargs):
    """Get first result from this.

    Beware: get() ignores the LIMIT clause on GQL queries.

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

    Returns:
      First result from running the query if there are any, else None.
    """
    results = self.run(limit=1, **kwargs)
    try:
      return results.next()
    except StopIteration:
      return None 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:18,代碼來源:__init__.py

示例6: count

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def count(self, limit=1000, **kwargs):
    """Number of entities this query fetches.

    Beware: count() ignores the LIMIT clause on GQL queries.

    Args:
      limit: A number. If there are more results than this, stop short and
        just return this number. Providing this argument makes the count
        operation more efficient.
      kwargs: Any keyword arguments accepted by datastore_query.QueryOptions().

    Returns:
      Number of entities this query fetches.
    """
    raw_query = self._get_query()
    result = raw_query.Count(limit=limit, **kwargs)
    self._last_raw_query = raw_query

    return result 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:21,代碼來源:__init__.py

示例7: fetch

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def fetch(self, limit, offset=0, **kwargs):
    """Return a list of items selected using SQL-like limit and offset.

    Always use run(limit=...) instead of fetch() when iterating over a query.

    Beware: offset must read and discard all skipped entities. Use
    cursor()/with_cursor() instead.

    Args:
      limit: Maximum number of results to return.
      offset: Optional number of results to skip first; default zero.
      kwargs: Any keyword arguments accepted by datastore_query.QueryOptions().

    Returns:
      A list of db.Model instances.  There may be fewer than 'limit'
      results if there aren't enough results to satisfy the request.
    """
    if limit is None:
      kwargs.setdefault('batch_size', datastore._MAX_INT_32)
    return list(self.run(limit=limit, offset=offset, **kwargs)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:22,代碼來源:__init__.py

示例8: __iter__

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def __iter__(self):
    query = self._key_range.make_ascending_datastore_query(
        self._query_spec.entity_kind, filters=self._query_spec.filters)

    connection = datastore_rpc.Connection()
    query_options = datastore_query.QueryOptions(
        batch_size=self._query_spec.batch_size,
        start_cursor=self._cursor,
        produce_cursors=True)




    self._query = datastore_query.ResultsIterator(
        query.GetQuery().run(connection, query_options))
    for entity_proto in self._query:
      yield entity_proto 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:19,代碼來源:datastore_range_iterators.py

示例9: _iter_key_range

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def _iter_key_range(self, k_range):
    assert hasattr(self, "start_time_us"), "start_time_us property was not set"
    if self._ns_range is None:
      # _iter_ns_range will have already have dealt with unapplied jobs so only
      # handle the case where it would not have been called.
      self._apply_key_range(k_range)

    raw_entity_kind = self._get_raw_entity_kind(self._entity_kind)
    query = k_range.make_ascending_datastore_query(
        raw_entity_kind, keys_only=True, filters=self._filters)
    for key in query.Run(
        config=datastore_query.QueryOptions(batch_size=self._batch_size)):
      yield key, key 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:15,代碼來源:input_readers.py

示例10: _make_query

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def _make_query(self):
    qry = Message.query().order(-Message.when)
    options = datastore_query.QueryOptions(batch_size=13, limit=43)
    return qry, options 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:6,代碼來源:main.py

示例11: Hint

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def Hint(self, hint):
    """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
    """
    if hint is not self.__query_options.hint:
      self.__query_options = datastore_query.QueryOptions(
          hint=hint, config=self.__query_options)
    return self 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:36,代碼來源:datastore.py

示例12: GetQueryOptions

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def GetQueryOptions(self):
    """Returns a datastore_query.QueryOptions for the current instance."""
    return self.__query_options 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:5,代碼來源:datastore.py

示例13: Run

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def Run(self, **kwargs):
    """Runs this query.

    If a filter string is invalid, raises BadFilterError. If a filter value is
    invalid, raises BadValueError. If an IN filter is provided, and a sort
    order on another property is provided, raises BadQueryError.

    If you know in advance how many results you want, use limit=#. It's
    more efficient.

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

    Returns:
      # an iterator that provides access to the query results
      Iterator
    """
    config = _GetConfigFromKwargs(kwargs, convert_rpc=True,
                                  config_class=datastore_query.QueryOptions)
    itr = Iterator(self.GetBatcher(config=config))

    self.__index_list_source = itr.GetIndexList

    self.__cursor_source = itr.cursor

    self.__compiled_query_source = itr._compiled_query
    return itr 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:29,代碼來源:datastore.py

示例14: __setstate__

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def __setstate__(self, state):

    if '_Query__query_options' not in state:
      state['_Query__query_options'] = datastore_query.QueryOptions(
        keys_only=state.pop('_Query__keys_only'),
        produce_cursors=state.pop('_Query__compile'),
        start_cursor=state.pop('_Query__cursor'),
        end_cursor=state.pop('_Query__end_cursor'))
    self.__dict__ = state 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:11,代碼來源:datastore.py

示例15: _ToPb

# 需要導入模塊: from google.appengine.datastore import datastore_query [as 別名]
# 或者: from google.appengine.datastore.datastore_query import QueryOptions [as 別名]
def _ToPb(self, limit=None, offset=None, count=None):

    query_options = datastore_query.QueryOptions(
        config=self.GetQueryOptions(),
        limit=limit,
        offset=offset,
        batch_size=count)
    return self.GetQuery()._to_pb(_GetConnection(), query_options) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:10,代碼來源:datastore.py


注:本文中的google.appengine.datastore.datastore_query.QueryOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。