Kitura / Kitura-CouchDB

CouchDB adapter for Kitura
Apache License 2.0
51 stars 29 forks source link

feat: Add decodeDocuments() to AllDatabaseDocuments #97

Closed Andrew-Lees11 closed 5 years ago

Andrew-Lees11 commented 5 years ago

Description

The AllDatabaseDocuments struct returns a [[String: Any]] since it can be an array of multiple different types of Document. This PR adds a helper function:

decodeDocuments<T: Document>(ofType: T.Type) -> [T]

which will decode you all the document of the given type. This saves the user from having to handle the raw JSON.

We also add a new initializer for BulkDocuments:

init<T: Document>(encoding: [T])

That will create a bulk document struct by encoding an array of Documents instead of from a [[String: Any]].

Finally we have updated the copyright to 2019.

Motivation and Context

Despite the general improvement of the API, the retrieveAll and Bulk functions still use raw JSON that needs to be decoded into regular objects. Through supporting these new methods, this is now achievable without having to worry about manual serialization.

How Has This Been Tested?

I have tested this function for the only two possible use cases regarding the parameter passed to retrieveAll, and each case has been tested twice over.

Checklist: