This commit is contained in:
2023-09-27 09:33:00 +02:00
parent 2de7f2fea1
commit 00d7456f89
6 changed files with 60 additions and 2 deletions

19
app/db.py Normal file
View File

@@ -0,0 +1,19 @@
from flask import current_app, g
from werkzeug.local import LocalProxy
from flask_pymongo import PyMongo
def get_db():
"""
Configuration method to return db instance
"""
db = getattr(g, "_database", None)
if db is None:
db = g._database = PyMongo(current_app).db
return db
# Use LocalProxy to read the global db instance with just `db`
db = LocalProxy(get_db)