Table of contents

Couchdb plugins analysis

(original discussion is at https://github.com/cozy/cozy-stack/issues/9)

Existing packages

https://github.com/timjacobi/go-couchdb

https://github.com/zemirco/couchdb

https://github.com/rhinoman/couchdb-go

https://github.com/dustin/go-couch

Plan B - Make our own from net/http

If we go this way, it will be a good idea to look at the code of the other packages for each function, some pitfalls could be avoided :

ex:

Considerations on how we will use it

(see the architecture for more info)

Analysis

Going further (thanks @tomquest)

Another advantage of a DIY solution: building exactly what stack needs. This is orienting the CouchDB access code for Cozy usage. And this could be implemented as a DSL.

For example: (if I understand the architecture, the goal is for an User to have many Databases, one for each DocumentType)

// Create an Email
couchdb
    .Doc(anEmail) // deduce the database from the type of the parameters
    .Create()
    // .Update()
    // .Delete()
// List emails from 100 to 200
emails = couchdb
    .emails() // pick the appropriate database
    .Offset(100)
    .Limit(200)
    .Order(DATE, DESC)
    .select() // Create the adhoc CouchDb query (`Mango` style ?)

BTW, couchdb could be an already configured object with the appropriate user credentials.

Pros:

Cons:

Current decision

We will make our own driver by cherry picking relevant codes in other libraries.