I've got a pretty straightforward question. I intend to make a flask application that may end up making some complex SQL queries. For this reason, I have decided not to use an ORM and plus I prefer writing my own SQLs.
I wrote some simple SQLs for reading/writing data in a postgres function and then used psycopg2 to make function calls. I am thinking this approach would be better than writing raw SQLs as it would be easy to maintain.
Does anyone know of any pitfalls in taking this approach, or any limitations specific to psycopg2? Thank you.
An ORM can help you a lot, even if your application is Postgres only. I had to support really complicated deploys in different OS and I know ORMs can save you a lot of work and pain when requirements change. Definitely has some (small!) performance hit, but you can avoid most of the slow path when it is really important (bulk inserts/updates, plain SQL, etc.).
I'll take SQLAlchemy as an example, but most ORMs will have equivalent features.
psycopg2or other Postgres driver. No ORM I remember has its own driver. Once upon a time, I had unicode issues with
psycopg2(probably I was doing something wrong) and just changed SQLAlchemy to use another driver and worked fine. Other time, I wanted to run my application with PyPy and
psycopg2was not supported.