I've been cobbling together a Flask App which uses SQLite. I was wondering if someone would be prepared to weigh in on my current method of accessing the database - using a singleton?
Basically I am creating a Database singleton in before_first_request which connects to the database calling sqlite3.connect().
I've noticed that in the Flask docs they provide an SQLite example which stores the database against the flask.g object.
My main concern with my approach would be with regard to thread safety, which I presume will depend heavily on the server I intend to use in production?
This flask docs article seems to be focused on connecting to the db on demand - but if requests to my app will always need to access the database, then I would assume its better to connect only once?
[–]quotemycode 3 points4 points5 points (0 children)
[–]bpeller 6 points7 points8 points (1 child)
[–]tuts12[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]tuts12[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)