当前位置: 首页>>代码示例>>Python>>正文


Python db.Query方法代码示例

本文整理汇总了Python中google.appengine.ext.db.Query方法的典型用法代码示例。如果您正苦于以下问题:Python db.Query方法的具体用法?Python db.Query怎么用?Python db.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.ext.db的用法示例。


在下文中一共展示了db.Query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ClearDatastore

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def ClearDatastore(request):
    """Clears data in the datastore, many at a time (for admins only)."""
    clear = (None, 'None')
    atatime = 10

    msg = ''
    query = db.Query(clear[0])
    rows = query.fetch(atatime)
    length = len(rows)
    if length is 0:
        msg += 'No more rows to delete<br>'
    else:
        msg += 'Deleting %s %s<br>' % (length, clear[1])
        db.delete(rows)
        query = db.Query(clear[0])
        more = query.fetch(1)
        if len(more) is not 0:
            msg += 'Now do it again!'
            msg += '<script>window.location.href="/reflows/clear_datastore";</script>'
    return http.HttpResponse(msg) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:util.py

示例2: _get_query

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def _get_query(self, filters={}, inequality_prop=None,
        inequality_filters={}, orderings=[], order_directions={}):
        """Builds a db.Query.

        Returns:
          A google.appengine.ext.db.Query instance.
        """
        query = self.__class__.query_class(self._model_class,
            keys_only=self._keys_only)

        if self._ancestor:
            query.ancestor(self._ancestor)

        if inequality_prop and inequality_filters:
            for operator, value in inequality_filters.iteritems():
                query.filter(inequality_prop + ' ' + operator, value)

        for prop, value in filters.iteritems():
            query.filter(prop + ' =', value)

        for prop in orderings:
            query.order(order_directions[prop] + prop)

        return query 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:pager.py

示例3: __iter__

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def __iter__(self):
    """Iterate over entities.

    Yields:
      db model entities or ndb model entities if the model is defined with ndb.
    """
    for ns in self._ns_range:
      self._query = self._property_range.make_query(ns)
      if isinstance(self._query, db.Query):
        if self._cursor:
          self._query.with_cursor(self._cursor)
        for model_instance in self._query.run(
            batch_size=self._query_spec.batch_size,
            keys_only=self._query_spec.keys_only):
          yield model_instance
      else:
        self._query = self._query.iter(batch_size=self._query_spec.batch_size,
                                       keys_only=self._query_spec.keys_only,
                                       start_cursor=self._cursor,
                                       produce_cursors=True)
        for model_instance in self._query:
          yield model_instance
      self._cursor = None
      if ns != self._ns_range.namespace_end:
        self._ns_range = self._ns_range.with_start_after(ns) 
开发者ID:elsigh,项目名称:browserscope,代码行数:27,代码来源:datastore_range_iterators.py

示例4: to_json

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def to_json(self):
    """Inherit doc."""
    cursor_object = False
    if self._query is not None:
      if isinstance(self._query, db.Query):
        self._cursor = self._query.cursor()
      else:
        cursor_object = True
        self._cursor = self._query.cursor_after().to_websafe_string()
    else:
      self._cursor = None

    return {"property_range": self._property_range.to_json(),
            "query_spec": self._query_spec.to_json(),
            "cursor": self._cursor,
            "ns_range": self._ns_range.to_json_object(),
            "name": self.__class__.__name__,
            "cursor_object": cursor_object}

  # TODO(user): it sucks we need to handle cursor_to_str in many places.
  # In the long run, datastore adaptor refactor will take care of this as
  # we will only need to deal with low level datastore API after that.
  # Thus we will not add Cursor as a json primitive MR should understand. 
开发者ID:elsigh,项目名称:browserscope,代码行数:25,代码来源:datastore_range_iterators.py

示例5: __iter__

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def __iter__(self):
    self._query = self._key_range.make_ascending_query(
        util.for_name(self._query_spec.model_class_path),
        filters=self._query_spec.filters)

    if isinstance(self._query, db.Query):
      if self._cursor:
        self._query.with_cursor(self._cursor)
      for model_instance in self._query.run(
          batch_size=self._query_spec.batch_size,
          keys_only=self._query_spec.keys_only):
        yield model_instance
    else:
      self._query = self._query.iter(batch_size=self._query_spec.batch_size,
                                     keys_only=self._query_spec.keys_only,
                                     start_cursor=self._cursor,
                                     produce_cursors=True)
      for model_instance in self._query:
        yield model_instance 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:21,代码来源:datastore_range_iterators.py

示例6: load

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def load(cls, backup_id, kind_name, shard_id=None):
    """Retrieve SchemaAggregationResult from the Datastore.

    Args:
      backup_id: Required BackupInformation Key.
      kind_name: Required kind name as string.
      shard_id: Optional shard id as string.

    Returns:
      SchemaAggregationResult iterator or an entity if shard_id not None.
    """
    parent = cls._get_parent_key(backup_id, kind_name)
    if shard_id:
      key = datastore_types.Key.from_path(cls.kind(), shard_id, parent=parent)
      return SchemaAggregationResult.get(key)
    else:
      return db.Query(cls).ancestor(parent).run() 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:19,代码来源:backup_handler.py

示例7: make_query

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def make_query(self, ns):
    """Make a query of entities within this range.

    Query options are not supported. They should be specified when the query
    is run.

    Args:
      ns: namespace of this query.

    Returns:
      a db.Query or ndb.Query, depends on the model class's type.
    """
    if issubclass(self.model_class, db.Model):
      query = db.Query(self.model_class, namespace=ns)
      for f in self.filters:
        query.filter("%s %s" % (f[0], f[1]), f[2])
    else:
      query = self.model_class.query(namespace=ns)
      for f in self.filters:
        query = query.filter(ndb.FilterNode(*f))
    return query 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:23,代码来源:property_range.py

示例8: make_directed_query

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def make_directed_query(self, kind_class, keys_only=False):
    """Construct a query for this key range, including the scan direction.

    Args:
      kind_class: A kind implementation class (a subclass of either
        db.Model or ndb.Model).
      keys_only: bool, default False, use keys_only on Query?

    Returns:
      A db.Query or ndb.Query instance (corresponding to kind_class).

    Raises:
      KeyRangeError: if self.direction is not in (KeyRange.ASC, KeyRange.DESC).
    """
    if ndb is not None:
      if issubclass(kind_class, ndb.Model):
        return self.make_directed_ndb_query(kind_class, keys_only=keys_only)
    assert self._app is None, '_app is not supported for db.Query'
    direction = self.__get_direction("", "-")
    query = db.Query(kind_class, namespace=self.namespace, keys_only=keys_only)
    query.order("%s__key__" % direction)

    query = self.filter_query(query)
    return query 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:26,代码来源:__init__.py

示例9: make_directed_datastore_query

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def make_directed_datastore_query(self, kind, keys_only=False):
    """Construct a query for this key range, including the scan direction.

    Args:
      kind: A string.
      keys_only: bool, default False, use keys_only on Query?

    Returns:
      A datastore.Query instance.

    Raises:
      KeyRangeError: if self.direction is not in (KeyRange.ASC, KeyRange.DESC).
    """
    direction = self.__get_direction(datastore.Query.ASCENDING,
                                     datastore.Query.DESCENDING)
    query = datastore.Query(kind, _app=self._app, keys_only=keys_only)
    query.Order(("__key__", direction))

    query = self.filter_datastore_query(query)
    return query 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:22,代码来源:__init__.py

示例10: make_ascending_query

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def make_ascending_query(self, kind_class, keys_only=False, filters=None):
    """Construct a query for this key range without setting the scan direction.

    Args:
      kind_class: A kind implementation class (a subclass of either
        db.Model or ndb.Model).
      keys_only: bool, default False, query only for keys.
      filters: optional list of filters to apply to the query. Each filter is
        a tuple: (<property_name_as_str>, <query_operation_as_str>, <value>).
        User filters are applied first.

    Returns:
      A db.Query or ndb.Query instance (corresponding to kind_class).
    """
    if ndb is not None:
      if issubclass(kind_class, ndb.Model):
        return self.make_ascending_ndb_query(
            kind_class, keys_only=keys_only, filters=filters)
    assert self._app is None, '_app is not supported for db.Query'
    query = db.Query(kind_class, namespace=self.namespace, keys_only=keys_only)
    query.order("__key__")

    query = self.filter_query(query, filters=filters)
    return query 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:26,代码来源:__init__.py

示例11: make_ascending_datastore_query

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def make_ascending_datastore_query(self, kind, keys_only=False, filters=None):
    """Construct a query for this key range without setting the scan direction.

    Args:
      kind: A string.
      keys_only: bool, default False, use keys_only on Query?
      filters: optional list of filters to apply to the query. Each filter is
        a tuple: (<property_name_as_str>, <query_operation_as_str>, <value>).
        User filters are applied first.

    Returns:
      A datastore.Query instance.
    """
    query = datastore.Query(kind,
                            namespace=self.namespace,
                            _app=self._app,
                            keys_only=keys_only)
    query.Order(("__key__", datastore.Query.ASCENDING))

    query = self.filter_datastore_query(query, filters=filters)
    return query 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:23,代码来源:__init__.py

示例12: connect

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def connect(server, app_id=None, username=None, password=None, secure=True):
    """Sets up a connection to an app that has the remote_api handler."""
    if not app_id:
        app_id = get_app_id()
    print('Application ID: %s' % app_id)
    print('Server: %s' % server)
    if not username:
        username = raw_input('Username: ')
    else:
        print('Username: %s' % username)
    # Sets up users.get_current_user() inside of the console
    os.environ['USER_EMAIL'] = username
    if not password:
        password = getpass.getpass('Password: ')
    remote_api_stub.ConfigureRemoteDatastore(
        app_id, '/remote_api', lambda: (username, password), server,
        secure=secure)

    db.Query().count()  # force authentication to happen now 
开发者ID:google,项目名称:personfinder,代码行数:21,代码来源:remote_api.py

示例13: get

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def get(self):
        entries = db.Query(Entry).order('-published').fetch(limit=5)
        if not entries:
            if not self.current_user or self.current_user.administrator:
                self.redirect("/compose")
                return
        self.render("home.html", entries=entries) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:blog.py

示例14: post

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def post(self):
        key = self.get_argument("key", None)
        if key:
            entry = Entry.get(key)
            entry.title = self.get_argument("title")
            entry.body_source = self.get_argument("body_source")
            entry.html = tornado.escape.linkify(
                self.get_argument("body_source"))
        else:
            title = self.get_argument("title")
            slug = unicodedata.normalize("NFKD", title).encode(
                "ascii", "ignore")
            slug = re.sub(r"[^\w]+", " ", slug)
            slug = "-".join(slug.lower().strip().split())
            if not slug: slug = "entry"
            while True:
                existing = db.Query(Entry).filter("slug =", slug).get()
                if not existing or str(existing.key()) == key:
                    break
                slug += "-2"
            entry = Entry(
                author=self.current_user,
                title=title,
                slug=slug,
                body_source=self.get_argument("body_source"),
                html=tornado.escape.linkify(self.get_argument("body_source")),
            )
        entry.put()
        self.redirect("/entry/" + entry.slug) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:31,代码来源:blog.py

示例15: UpdateRecentTests

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Query [as 别名]
def UpdateRecentTests(request):
  max_recent_tests = 10
  visible_categories = all_test_sets.GetVisibleTestSets()
  #logging.info('visible_categories %s' % visible_categories)

  prev_recent_tests = memcache.get(util.RECENT_TESTS_MEMCACHE_KEY)
  prev_result_parent_key = None
  if prev_recent_tests:
    prev_result_parent_key = prev_recent_tests[0]['result_parent_key']

  recent_tests = []
  recent_query = db.Query(ResultParent).order('-created').filter('category IN',
      [vis.category for vis in visible_categories])
  for result_parent in recent_query.fetch(max_recent_tests):
    if str(result_parent.key()) == prev_result_parent_key:
      num_needed = max_recent_tests - len(recent_tests)
      if num_needed == max_recent_tests:
        return http.HttpResponse('No update needed.')
      else:
        recent_tests.extend(prev_recent_tests[:num_needed])
        break
    recent_scores = result_parent.GetResults()
    test_set = all_test_sets.GetTestSet(result_parent.category)
    visible_test_keys = [t.key for t in test_set.VisibleTests()]
    recent_stats = test_set.GetStats(visible_test_keys, recent_scores)
    recent_tests.append({
        'result_parent_key': str(result_parent.key()),
        'category': result_parent.category,
        'created': result_parent.created,
        'user_agent_pretty': result_parent.user_agent.pretty(),
        'score': recent_stats['summary_score'],
        'display': recent_stats['summary_display'],
        })
  #logging.info('Setting recent tests: %s' % recent_tests)
  memcache.set(util.RECENT_TESTS_MEMCACHE_KEY, recent_tests,
               time=settings.STATS_MEMCACHE_TIMEOUT)
  #logging.info('Read recent tests: %s' %
  #    memcache.get(key=util.RECENT_TESTS_MEMCACHE_KEY))
  return http.HttpResponse('Done') 
开发者ID:elsigh,项目名称:browserscope,代码行数:41,代码来源:cron.py


注:本文中的google.appengine.ext.db.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。