我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用google.appengine.ext.ndb.QueryOptions()。
def make_ascending_ndb_query(self, kind_class, keys_only=False, filters=None): """Construct an NDB query for this key range, without the scan direction. Args: kind_class: An ndb.Model subclass. keys_only: bool, default False, query only for keys. Returns: An ndb.Query instance. """ assert issubclass(kind_class, ndb.Model) if keys_only: default_options = ndb.QueryOptions(keys_only=True) else: default_options = None query = kind_class.query(app=self._app, namespace=self.namespace, default_options=default_options) query = self.filter_ndb_query(query, filters=filters) query = query.order(kind_class._key) return query
def ajax_reports(): offset = request.args.get('start', type=int) limit = request.args.get('length', type=int) search_term = request.args.get('search[value]') order_index = request.args.get('order[0][column]', type=int) order_dir = request.args.get('order[0][dir]') fields = [EmailReport.date_reported, EmailReport.reported_by, EmailReport.report_type, EmailReport.subject, EmailReport.status] query = EmailReport.domain_query(g.domain) total_count = query.count() # Setup the correct ordering order_field = EmailReport.key if order_index > 0: order_field = fields[order_index - 1] if order_dir == 'desc': order_field = -order_field query_options = ndb.QueryOptions(limit=limit, offset=offset) results = query.order(order_field).fetch(options=query_options, projection=fields) results_json = [result.to_dict() for result in results] return jsonify({ 'draw': int(request.args.get('draw')), 'recordsTotal': total_count, 'recordsFiltered' : total_count, 'data': results_json })
def make_directed_ndb_query(self, kind_class, keys_only=False): """Construct an NDB query for this key range, including the scan direction. Args: kind_class: An ndb.Model subclass. keys_only: bool, default False, use keys_only on Query? Returns: An ndb.Query instance. Raises: KeyRangeError: if self.direction is not in (KeyRange.ASC, KeyRange.DESC). """ assert issubclass(kind_class, ndb.Model) if keys_only: default_options = ndb.QueryOptions(keys_only=True) else: default_options = None query = kind_class.query(app=self._app, namespace=self.namespace, default_options=default_options) query = self.filter_ndb_query(query) if self.__get_direction(True, False): query = query.order(kind_class._key) else: query = query.order(-kind_class._key) return query