Pregunta

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?

¿Fue útil?

Solución

For SQLAlchemy you can achieve something like that using a smarter Session.

Just subclass the sqlalchemy.orm.Session class and override the get_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.Session in model/session.py and overridding the ming.Session.db property to return the right database.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top