Search code examples
pythonflaskpeewee

Using multiple databases with peewee


I'm writing a "multi tenant" application. It's going to be hosted on different subdomains, and based on which subdomain it's hosted, it should use a different database.

Is it possible to define, in execution time, which database peewee should be using? If I were using django, I'd just write a router that takes care of it, but I haven't found anything similar on peewee.

Am I missing something?

Thanks!

PS: A hack like this How to query several similar databases using Peewee?, where you need to know beforehand which class to invoke wouldn't work fine in my scenario


Solution

  • Instead of handling this in peewee, you could handle the db selection in flask using application factories with application dispatchers