nano icon indicating copy to clipboard operation
nano copied to clipboard

add reference to server in doc scope

Open dominicbarnes opened this issue 9 years ago • 3 comments

This PR adds the ability to get at the serverScope from a docScope. (which is not currently possible)

If you initialize nano with a db-name in your URL, (a common practice) it effectively becomes impossible to access the server scope:

var db = nano('http://localhost:5984/mydb');
// there is no way to access server scope, for something like server.auth()

In my case, I'm using a single database for my application, but I'm also trying to use _users for handling auth. I'm forced to create 2 different nano refs, which is just a little clumsy.

var server = nano('http://localhost:5984');
var db = server.use('mydb');

server.auth(); // user login
db.get(); // document retrieval

This PR adds support for the following:

var db = nano('http://localhost:5984/mydb');

db.server.auth(); // user login
db.get(); // document retrieval

While I could just say this is a convenience method, I think it's a little bit more than that since a common pattern like specifying a db-name completely excludes this functionality.

dominicbarnes avatar Oct 23 '16 04:10 dominicbarnes

Thanks for the contribution.

This has been moved to the ASF, so I'm unsure if I can accept and publish new versions of nano.

Please advise @janl @jo @rnewson

dscape avatar Jan 04 '17 13:01 dscape

Hi, best thing to do is so submit a PR against https://github.com/apache/couchdb-nano/ instead.

rnewson avatar Jan 05 '17 10:01 rnewson

I've ported this PR to the other repo

dominicbarnes avatar Jan 10 '17 15:01 dominicbarnes