Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/view queries #126

Merged
merged 4 commits into from
Mar 17, 2021
Merged

Feature/view queries #126

merged 4 commits into from
Mar 17, 2021

Conversation

panoukos41
Copy link
Contributor

Hey as I was using more features around Views and getting help from CouchDB Slack people I was told about this and thought now that the library supports Views it shouldn't be hard so I implemented the following.

Check it out when you have time and tell me if something needs to change, no rush, thanks for your time 😊

Feature Overview

By appending a /queries in a view URL you can execute this view with multiple query objects to get multiple results without calling the API multiple times. The only difference is that you add each query option in a json like this

{
  "queries": [
      { "key": "luke" }, // options
      ...
  ]
}

then you receive a response that has only one object which contains one result per query in the same order

{
  "results": [
    {
      "total_rows": 20,
      "offset" : 10,
      "rows": [ ... ]
    },
    ...
  ]
}

I added an Internal Dto CouchViewQueryResult to deserialize the result object.

Then added the following methods: (Task and some parameters omitted for brevity)

List<List<CouchView<TKey, TValue, TSource>>> GetViewQueryAsync<...>(..., IEnumerable<CouchViewOptions<TKey>>);

List<CouchViewList<TKey, TValue, TSource>> GetDetailedViewQueryAsync<...>(..., IEnumerable<CouchViewOptions<TKey>>);

I also created two tests that query the same view method with the same options twice since it doesn't matter if you use the same options multiple times, then the tests check if the produced request/response objects are of the expected format.

Questions

  1. For the first method that doesn't include details is it okay to return a list with multiple lists or should it be an array that contains the lists?
  2. Since this feature is available for CouchDB v2.2 and later should I add a <remarks></remarks> stating the version?

This feature exists in CouchDB v2.2 and later and is described with more details here

@matteobortolazzo
Copy link
Owner

Great job man! Is this documented anywhere?

I don't like accessing results by index, it makes no sense to me, a key is better, but since it's Couch API it's ok.

About questions:

  • Yeah, I would use an array of list
  • No, 2.2 is old enough

The last thing, I would use IList instead of IEnumerable as I don't want to risk enumerations inside the serialization in case people do stupid stuff like an SQL query.

Refactor to use an array of list instead of a list of list.

Refactor queries parameter to `IList` instead of an `IEnumerable`

Refactor Tests to use `Length` as they are arrays now

Refactor README.md example to be correct.
@panoukos41
Copy link
Contributor Author

This is what I read when I was testing it and then using it before implementing it which shows the request and response objects 😄 in detail, it just shows it for the _all_docs instead of custom views but you do the same.

I made the detailed version to return an array of CouchViewList so that it is in line with the simple method.

I have created one example in the Views section maybe add the link to the docs there?

@matteobortolazzo matteobortolazzo merged commit af22327 into matteobortolazzo:dev Mar 17, 2021
@matteobortolazzo
Copy link
Owner

The example is correct, I can merge this one

@panoukos41 panoukos41 deleted the feature/view_queries branch March 18, 2021 00:27
@matteobortolazzo
Copy link
Owner

3.1.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants