BTW, don't move your HTML into the db :-) Separate presentation and data logic.
(We are teaching a course[1] in Sweden on programming against PostgreSQL. It focuses on much of this as well as trying to look under the hood to deal with what happens when the abstraction fails to deliver what is expected.)
At the end, this is a longish path and one that took me personally a long time to make. But it is something that he more we share, the better off others will be I think.
[1]https://edument.se/education/categories/sql/advanced-postgre...