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

Array as QueryParameters.Key value #2

Closed
leledumbo opened this issue Apr 7, 2016 · 2 comments
Closed

Array as QueryParameters.Key value #2

leledumbo opened this issue Apr 7, 2016 · 2 comments

Comments

@leledumbo
Copy link

I have a design document with map function that use array as key for easy grouping. When queried directly, e.g. in browser / through curl, it works correctly, e.g.:

curl http:https://localhost:5984/db/_design/doc/_view/func?key=["a",1]

However, querying from this library, using View.Get doesn't work. This is due to QueryParameters (and therefore its Key member) being URL encoded so if I do:

// assume view is of type View and correctly retrieved from Database
key = `["a",1]`
params := couchdb.QueryParameters{
  Key: &key,
}
resp, err := view.Get("func", params)

It will instead query for http:https://localhost:5984/db/_design/doc/_view/func?key=%5B%22a%22%2C1%5D
which CouchDB doesn't consider as array value.

Is there any way to overcome this?

@zemirco
Copy link
Owner

zemirco commented Apr 9, 2016

Are you using the latest version of the couchdb package? I have some tests where an array is used as StartKey and EndKey and they work fine.

params := QueryParameters{
  StartKey: pointer.String(fmt.Sprintf("[%q,%d]", "foo2", 20)),
  EndKey:   pointer.String(fmt.Sprintf("[%q,%d]", "foo2", 20)),
}

The same should work for the Key field.

@leledumbo
Copy link
Author

OK, using fmt.Sprintf("[%q,%q]") seems working, no idea why fmt.Sprintf("[%q,%d]") causes invalid JSON.

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

No branches or pull requests

2 participants