slouch
slouch copied to clipboard
Have to add quotes and escape them for startkey/endkey to work
database.doc.all "dbname", {
startkey: "\"alpha\"",
endkey: "\"bravo\ufff0\"",
include_docs: true
}
.each (row) => ...
Is this by design? This isn't the case for PouchDB. The extra escaped quotes are ugly.
(sorry for the coffeescript!)
This isn't by design. I believe this is the format that CouchDB expects and I agree that it is ugly. I'll take a closer look when I get a chance. Thanks for bringing this up!
I got a chance to look closer into this and this aspect appears to be something rooted in the CouchDB API. For example, you have to wrap the key in quotes even when using just curl:
curl -X GET 'localhost:5984/mydb/_all_docs?include_docs=true&startkey="bravo"'
As such, I'm not really sure that making the change in Slouch is the best move at this point.
You can make this a little prettier by using a single quote to wrap the keys, e.g.
slouch.doc.all('dbname', { startkey: '"bravo"' }).each(function (doc) {
console.log(doc);
});
You have to wrap the startkey in quotes because the value passed to couchdb has to be a valid json object.
If you're trying to provide an interface for people moving from curl then I guess it makes sense to do this. I'm not sure what Nano does, but for PouchDB you don't have to. So I guess it comes down to who is your target user.