in lib/src/grpc_api_impl/datastore_impl.dart [295:365]
static _QueryPageImpl fromQueryResult(
RunQueryRequest request,
DatastoreClient clientGRPCStub,
_Codec codec,
int? offset,
int alreadySkipped,
int? remainingNumberOfEntities,
QueryResultBatch batch) {
// If we have an offset: Check that in total we haven't skipped too many.
if (offset != null &&
offset > 0 &&
batch.hasSkippedResults() &&
batch.skippedResults > (offset - alreadySkipped)) {
throw raw.DatastoreError(
'Datastore was supposed to skip $offset entities, '
'but response indicated '
'${batch.skippedResults + alreadySkipped} entities were '
'skipped (which is more).');
}
// If we have a limit: Check that in total we haven't gotten too many.
if (remainingNumberOfEntities != null &&
remainingNumberOfEntities > 0 &&
batch.entityResults.length > remainingNumberOfEntities) {
throw raw.DatastoreError(
'Datastore returned more entitites (${batch.entityResults.length}) '
'then the limit was ($remainingNumberOfEntities).');
}
// If we have a limit: Calculate the remaining limit.
int? remainingEntities;
if (remainingNumberOfEntities != null && remainingNumberOfEntities > 0) {
remainingEntities =
remainingNumberOfEntities - batch.entityResults.length;
}
// Determine if this is the last query batch.
bool isLast;
if (!batch.hasMoreResults()) {
throw raw.DatastoreError(
'Datastore was supposed to specify the "moreResults" field '
'in the query response, but it was missing.');
}
if (batch.moreResults ==
QueryResultBatch_MoreResultsType.MORE_RESULTS_AFTER_LIMIT ||
batch.moreResults ==
QueryResultBatch_MoreResultsType.MORE_RESULTS_AFTER_CURSOR ||
batch.moreResults == QueryResultBatch_MoreResultsType.NO_MORE_RESULTS) {
isLast = true;
} else if (batch.moreResults ==
QueryResultBatch_MoreResultsType.NOT_FINISHED) {
isLast = false;
} else {
throw raw.DatastoreError(
'Datastore returned an unknown "moreResults" field in the query '
'response');
}
// If we have an offset: Calculate the new number of skipped entities.
int skipped = alreadySkipped;
if (offset != null && offset > 0 && batch.hasSkippedResults()) {
skipped += batch.skippedResults;
}
final entities = batch.entityResults.map((EntityResult result) {
return codec.decodeEntity(result.entity);
}).toList();
return _QueryPageImpl(request, clientGRPCStub, codec, batch.endCursor,
entities, isLast, offset, skipped, remainingEntities);
}