Front-end application database context with Peewee supporting pooling and automatic reconnection?

Viewed 20

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:

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:

  1. Works with DatabaseProxy and playhouse.db_url.connect and can support at least SQLite and Postgres.
  2. Keeps a pool of N connections which are managed internally and if the connection is lost then a retry is attempted until a timeout.
  3. Indeed, I need a connect timeout instead of keep waiting forever to fail.
  4. The connection pooling part: automatic recycling and closing of idle connections.
  5. Robust automatic retrial on OperationalError due 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.

0 Answers
Related