def Query(self, query, filters, orders): """Perform a query on this pseudo-kind. Args: query: the original datastore_pb.Query. filters: the filters from query. orders: the orders from query. Returns: (results, remaining_filters, remaining_orders) results is a list of entity_pb.EntityProto remaining_filters and remaining_orders are the filters and orders that should be applied in memory """ kind_range = datastore_stub_util.ParseKindQuery(query, filters, orders) app_namespace_str = datastore_types.EncodeAppIdNamespace( query.app(), query.name_space()) kinds = [] for app_namespace, kind in self._stub._GetAllEntities(): if app_namespace != app_namespace_str: continue kind = kind.decode('utf-8') if not kind_range.Contains(kind): continue kinds.append( datastore.Entity(self.name, name=kind, _app=query.app(), namespace=query.name_space())._ToPb()) return (kinds, [], [])
def Query(self, entities, query, filters, orders): """Perform a query on this pseudo-kind. Args: entities: all the app's entities. query: the original datastore_pb.Query. filters: the filters from query. orders: the orders from query. Returns: (results, remaining_filters, remaining_orders) results is a list of datastore.Entity remaining_filters and remaining_orders are the filters and orders that should be applied in memory """ kind_range = datastore_stub_util.ParseKindQuery(query, filters, orders) app_namespace_str = datastore_types.EncodeAppIdNamespace( query.app(), query.name_space()) kinds = [] for app_namespace, kind in entities: if app_namespace != app_namespace_str: continue if not kind_range.Contains(kind): continue kinds.append(datastore.Entity(self.name, name=kind)) return (kinds, [], [])
def Query(self, query, filters, orders): """Perform a query on this pseudo-kind. Args: query: the original datastore_pb.Query filters: the filters from query orders: the orders from query Returns: A query cursor to iterate over the query results, or None if the query is invalid. """ kind_range = datastore_stub_util.ParseKindQuery(query, filters, orders) conn = self._stub._GetConnection() cursor = None try: prefix = self._stub._GetTablePrefix(query) filters = [] def AddExtremeFilter(extreme, inclusive, is_end): """Add filter for kind start/end.""" if not is_end: if inclusive: op = datastore_pb.Query_Filter.GREATER_THAN_OR_EQUAL else: op = datastore_pb.Query_Filter.GREATER_THAN else: if inclusive: op = datastore_pb.Query_Filter.LESS_THAN_OR_EQUAL else: op = datastore_pb.Query_Filter.LESS_THAN filters.append(('kind', op, extreme)) kind_range.MapExtremes(AddExtremeFilter) params = [] sql_filters = self._stub._CreateFilterString(filters, params) sql_stmt = ('SELECT kind FROM "%s!Entities" %s GROUP BY kind' % (prefix, sql_filters)) c = conn.execute(sql_stmt, params) kinds = [] for row in c.fetchall(): kinds.append( MakeEntityForQuery(query, self.name, ToUtf8(row[0]))) cursor = datastore_stub_util._ExecuteQuery(kinds, query, [], [], []) finally: self._stub._ReleaseConnection(conn) return cursor