queryCollection static method
Query a collection with JSONB filter.
The response body is {"items": [...]}. A filtered query reports
CollectionFrameResponse.totalCount only when wantTotal is true,
because the server must scan all matches to count them. To fetch the
next page, pass the response's CollectionFrameResponse.nextCursor as
cursor; a cursor takes precedence over offset.
Implementation
static Future<CollectionFrameResponse> queryCollection(
P2PStream stream, {
required PeerId ownerPeerId,
required String path,
Map<String, dynamic>? filter,
String? sortField,
bool? sortAsc,
int? limit,
int? offset,
String? cursor,
bool wantTotal = false,
}) async {
try {
final requestBytes = CollectionFrame.encodeRequest(
operation: 'QUERY',
ownerPeerId: ownerPeerId,
path: path,
filter: filter,
sortField: sortField,
sortAsc: sortAsc,
limit: limit,
offset: offset,
cursor: cursor,
wantTotal: wantTotal,
);
await _writeFrameStatic(stream, requestBytes);
final responseBytes = await _readFrameStatic(stream);
return CollectionFrame.decodeResponse(responseBytes);
} catch (e, stackTrace) {
_logger.severe('Error querying collection: $e', e, stackTrace);
rethrow;
}
}