getAllDocs method

Future getAllDocs({
  1. bool includeDocs = false,
  2. int? limit,
  3. String? startKey,
  4. String? endKey,
  5. List<String>? keys,
  6. bool descending = false,
})

Get all documents. The parameters should be self explanatory and are addative. Refer to the CouchDb documentation for further explanation.

Implementation

Future<dynamic> getAllDocs(
    {bool includeDocs = false,
    int? limit,
    String? startKey,
    String? endKey,
    List<String>? keys,
    bool descending = false}) {
  // Validate the parameters
  if ((limit != null) && (limit < 0)) {
    return _raiseException(WiltException.getAllDocsLimit);
  }

  var url = alldocs;

  // Check the parameters and build the URL as needed
  if (includeDocs) {
    url = _setURLParameter(url, 'include_docs', 'true');
  }

  if (limit != null) {
    url = _setURLParameter(url, 'limit', limit.toString());
  }

  if (startKey != null) {
    final jsonStartkey = '"$startKey"';
    url = _setURLParameter(url, 'startkey', jsonStartkey);
  }

  if (endKey != null) {
    final jsonEndkey = '"$endKey"';
    url = _setURLParameter(url, 'endkey', jsonEndkey);
  }

  if (descending) {
    url = _setURLParameter(url, 'descending', descending.toString());
  }

  if (keys != null) {
    final keyString = json.encode(keys);
    url = _setURLParameter(url, 'keys', keyString);
  }

  url = _conditionUrl(url);
  return _httpRequest('GET_ALLDOCS', url);
}