neumino / rethinkdbdash

An advanced Node.js driver for RethinkDB with a connection pool, support for streams etc.
MIT License
848 stars 108 forks source link

Change DB on the fly #327

Closed genyded closed 7 years ago

genyded commented 7 years ago

reQL and the core driver can use something like conn.use('marvel') to change the default database on the fly. Does this driver have something comparable since use does not seem to work?

marshall007 commented 7 years ago

@genyded you should be able to pass the db optarg to .run().

genyded commented 7 years ago

But then doesn't that have to be done on each/every query? The whole point of specifying/changing the default is to avoid having to do that. It's also likely we'll want to run the same query against 2 different targets - which I suppose we could do by passing it as a parameter, but then that parameter has to be passed on every call, which somewhat seems to defeat the whole purpose of abstracting.

Maybe I am missing something obvious, but I think that is why the use call exists everywhere else in the first place.

marshall007 commented 7 years ago

@genyded you can instantiate rethinkdbdash with db: 'foo', and foo will be used as the default database across all connections in the pool. Then you can call .run({ db: 'bar' }) to change the default database on the fly. Does that answer your question?

If something like conn.use(db) were supported, that would imply globally changing the default db across all connections in the pool, which is probably not what you want. It would be impossible to have any guarantee that a given query would be running against the intended db.

genyded commented 7 years ago

Yes it does and thanks for sticking with me and clarifying. Fairly new to all this and there are many moving parts!