shamblett / sporran

A PouchDB like browser application in Dart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect query string with getAllDocs function

radneran opened this issue · comments

Hi there, I was trying out this package and came across a bug with the getAllDocs function.

I have created a database with a single document and wanted to retrieve all the documents. However, I noticed that the includeDocs argument was not functioning as expected, i.e. total_rows was correct but no documents were being returned. After investigating further, I noticed that the query string was as follows:

/test///_all_docs?include_docs=true&limit=10&startkey=%22%22&endkey=%22%22&keys=%5B%5D

The issue here seems to be the endkey and keys parameters. Once those were removed, it functioned as expected. The following are the fixes I made to the getAllDocs function in sporran.dart:

 Future<JsonObjectLite<dynamic>> getAllDocs(
      {bool includeDocs = false,
      int limit = 10,
      String? startKey, // made optional
      String? endKey, // made optional
      List<String> keys = const <String>[],
      bool descending = false}) {
    final opCompleter = Completer<JsonObjectLite<dynamic>>();
    ......
    /* Get the document from CouchDb */
      _database.wilt
          .getAllDocs(
              includeDocs: includeDocs,
              limit: limit,
              startKey: startKey,
              endKey: endKey,
              // use null if keys is empty so that wilt will not include it in the query string
              keys: keys.isEmpty ? null : keys,
              descending: descending)
          .then(completer);

Thanks, good spot, package updated with the above fix and re published at version 6.2.0