I have come across a requirement that needs to access a set of databases in a Mongodb server, using TurboGear framework. There I need to list down the Databases, and allow the user to select one and move on. As far as I looked, TurboGear does facilitate multiple databases to use, but those needs to be specify beforehand in the development.ini.
Is there a way to just connect to the db server(or to a particular database first) and then get the list of databases and select one on the fly?
For SQLAlchemy you can achieve something like that using a smarter Session.
Just subclass the
sqlalchemy.orm.Sessionclass and override theget_bind(self, mapper=None, clause=None)method.That method is called each time the session has to decide which engine to use and is expected to return the engine itself. You can then store a list of engines wherever you prefer and return the correct one.
When using Ming/MongoDB the same can probably be achieved by subclassing the
ming.Sessionin model/session.py and overridding theming.Session.dbproperty to return the right database.