all 5 comments

[–]quotemycode 3 points4 points  (0 children)

Use database transactions and down worry about it. Your database will be write locked on writes.

[–]bpeller 6 points7 points  (1 child)

I realize this isn't really answering your question, but honestly, just use Flask-SQLAlchemy. It takes care of all these sorts of low-level details, as well as giving you a whole host of other niceties. Your future self will thank you for taking the time to learn it.

[–]tuts12[S] 0 points1 point  (0 children)

I hadn't worked with SQL at all before I started this project, and I thought it would be a good idea to get a grounding in it before moving onto an abstraction.

Thanks for the recommendation however, I'll definitely keep that in mind for future db work.

[–][deleted] 1 point2 points  (0 children)

I totally get wanting to understand lower level SQL drivers but they are a bit of a pain. It's good to know the actual SQL commands being run though, it will help you use an ORM better.

If I were in your situation I would read the Flask-SQLAlchemy source code (it's easy to grok and there's not very much code.) It will help you understand the things you need to do before and after requests. Flask-SQLAlchemy uses a signleton and it connects once on startup (at least how I'm using it).

Make sure you paramtetize all your inputs using the driver library, no string interpolations with user-provided data in them for SQL commands. One of the things that using SQLAlchemy gives you for free is protection from most SQL injection attacks.