def run_query(self, query): query_pb = query._ToPb() encoded_response = yield self._make_request('RunQuery', query_pb.Encode()) results_pb = datastore_pb.QueryResult(encoded_response) raise gen.Return( [Entity.FromPb(entity) for entity in results_pb.result_list()])
def run_query(self, query): entities = [] query_pb = query._ToPb() encoded_response = yield self._make_request('RunQuery', query_pb.Encode()) results_pb = datastore_pb.QueryResult(encoded_response) entities.extend( [Entity.FromPb(entity) for entity in results_pb.result_list()]) while results_pb.has_more_results() and len( results_pb.result_list()) >= 100: query_pb.set_offset(query_pb.offset() + len(results_pb.result_list())) encoded_response = yield self._make_request( 'RunQuery', query_pb.Encode()) results_pb = datastore_pb.QueryResult(encoded_response) entities.extend( [Entity.FromPb(entity) for entity in results_pb.result_list()]) raise gen.Return(entities)
def get(self, key, txid=None): request = datastore_pb.GetRequest() req_key = request.add_key() req_key.MergeFrom(key._ToPb()) if txid is not None: req_tx = request.mutable_transaction() req_tx.set_app(self.project_id) req_tx.set_handle(txid) encoded_response = yield self._make_request('Get', request.Encode()) get_response = datastore_pb.GetResponse(encoded_response) response_entity = get_response.entity(0).entity() if not response_entity.has_key(): return raise gen.Return(Entity.FromPb(response_entity))