I have a data model defined with Peewee and it is all good. Now I need to bookkeep some form of database context in an xlwings front end application but I'm not 100% sure how to proceed. I see couple of bits and pieces of information here and there but not 100% sure how to:
- https://docs.peewee-orm.com/en/2.10.2/peewee/database.html#connection-pooling
- https://docs.peewee-orm.com/en/2.10.2/peewee/database.html#automatic-reconnect
I'm already using a DatabaseProxy to deffer tying the model to a specific connection until runtime as I can target different vendors e.g. PROD -> Postgres and UT -> SQLite:
database_proxy = DatabaseProxy()
Furthermore, I use playhouse.db_url's connect way with a fully qualified URL. I need a "Database Context" that:
- Works with
DatabaseProxyandplayhouse.db_url.connectand can support at least SQLite and Postgres. - Keeps a pool of N connections which are managed internally and if the connection is lost then a retry is attempted until a timeout.
- Indeed, I need a connect timeout instead of keep waiting forever to fail.
- The connection pooling part: automatic recycling and closing of idle connections.
- Robust automatic retrial on
OperationalErrordue to short database outages.
I struggle to put all the pieces together here, for example, the playhouse.db_url.connect doesn't have retry or timeout arguments, it is also not clear how to decorate such connection with pooling and so on.