Use Werkzeug's LocalProxy to switch databases.