Thanks, Peter - I'd spotted that, but it means that throughout the
code I'd need to do stuff like:
"MyDocument.on(@account_db).by_name", (and also set the database on
document instances before saving them) ... which doesn't feel very
DRY.
The alternative, as I mentioned, is just setting each the database on
each document type once, at the start of the request. But this
doesn't feel right either (as you have to either maintain a list of
all document classes, or do some clunky meta-programming to find them
all).
I'm not sure which is worse. :)
On Sep 22, 11:52 pm, Peter Gumeson <
gume...@gmail.com> wrote:
> Have a look at the ClassProxy class in couchrest.
>
> Peter
>
>
>
> On Tue, Sep 22, 2009 at 5:40 AM, RicRoberts <
ricisb...@googlemail.com> wrote:
>
> > In a web framework like rails or sinatra for example, can anyone
> > suggest how best to specify a different database for CouchRest to use
> > on each request, based on the url? e.g.
http://mysite.com/my_couch_db/rest/of/url
>
> > I'm anticipating a small number of accounts (i.e. a few tens) and I'd
> > like to store data for different accounts in separate couch
> > databases. It'd be great if in a before_filter (or whatever), I could
> > set the site for the whole request, like this:
>
> > db = CouchRest.database("
http://127.0.0.1:5984/my_couch_db")
> > CouchRest::ExtendedDocument.use_database db
>
> > The CouchRest docs say not to change the model databases at runtime,
> > and the above code doesn't work in cases where couchrest is not
> > reloaded on each request - i.e. "production mode". Instead, I have to
> > call use_database on each individual model to get different requests
> > to use different dbs. Am I doing something silly here?
>
> > Any tips appreciated!
> > Cheers,
> > Ric
>
> --
> Peter Gumeson
>
gume...@gmail.com