Currently, a random dhrid is generated at the start of each request, which is then tied to a newly created database connection.
All database queries using app.db require passing in dhrid to identify the connection, which is not elegant and developer-friendly.
Thus, it is proposed that, a new class that inherits the db class be created. This class would be tied to request so it does not interfere with app object. This class would have dhrid embedded. When a database method is called, it would prepend the dhrid argument and call parent class method.
This change would make database connection handling much more elegant, as no dhrid needs to be passed in manually.
However, it is still worth investigating using FastAPI builtin database handlers for more idiomatic database connection management.
Currently, a random
dhridis generated at the start of each request, which is then tied to a newly created database connection.All database queries using
app.dbrequire passing indhridto identify the connection, which is not elegant and developer-friendly.Thus, it is proposed that, a new class that inherits the db class be created. This class would be tied to
requestso it does not interfere withappobject. This class would havedhridembedded. When a database method is called, it would prepend thedhridargument and call parent class method.This change would make database connection handling much more elegant, as no
dhridneeds to be passed in manually.However, it is still worth investigating using
FastAPIbuiltin database handlers for more idiomatic database connection management.