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

Add mango index & queries to couchdb package #50

Merged
merged 2 commits into from
Oct 18, 2016
Merged

Conversation

aenario
Copy link
Contributor

@aenario aenario commented Oct 17, 2016

This PR introduces mango queries to the couchdb package.

The API is as follow

index := mango.IndexOnFields('folderID', 'modificationDate')
couchdb.DefineIndex(prefix, doctype, index);

query := couchdb.FindRequest{
Filter: mango.Equal('folderID', myID), 
Sort: mango.SortBy{'modificationDate', mango.Asc}
}
var out []Files
couchdb.FindDocs(prefix, doctype, &query, &out)

func FindDocs(dbprefix, doctype string, req *FindRequest, results interface{}) error {
url := makeDBName(dbprefix, doctype) + "/_find"
// prepare a structure to receive the results
var response = findResponse{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var response *findResponse may be a bit more idiomatic

// but we will need to duplicate the couchdb UCA algorithm
type Filter interface {
ToMango() map[string]interface{}
MarshalJSON() ([]byte, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could inherit the json.Marshaler interface

@jinroh jinroh merged commit bc779a5 into cozy:master Oct 18, 2016
@aenario aenario deleted the mango branch October 18, 2016 09:52
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.

None yet

2 participants