Kitura-CouchDB icon indicating copy to clipboard operation
Kitura-CouchDB copied to clipboard

Improve documentation for queryByView with decodeDocuments

Open djones6 opened this issue 5 years ago • 1 comments

https://github.com/IBM-Swift/Kitura-CouchDB/pull/97 introduced the decodeDocuments helper function, and adds comments that elude to the fact that when querying documents from CouchDB, you must set the include_docs parameter to true for Couch to include the documents themselves in the response. However, the existing queryByView function does not document this requirement, and so it could be confusing that something like this does not work:

database.queryByView("fruitView", ofDesign: "fruitDesign", usingParameters: []) {
(documents, error) in
    let fruitDocs = documents?.decodeDocuments(ofType: Fruit.self)
    ....
}

The solution in this case is to add usingParameters: [.includeDocs(true)]. I feel this use-case should be discussed in the documentation for the queryByView function.

djones6 avatar Aug 21 '19 11:08 djones6

@djones6 thank you very much. I almost lost a hour to digging why decodeDocuments return empty array even for simple sample

MadGeorge avatar Sep 24 '19 13:09 MadGeorge