summaryrefslogtreecommitdiff
path: root/app/database.py
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonail.com>2022-03-21 18:09:50 -0500
committerstilbruch <stilbruch@protonail.com>2022-03-21 18:10:43 -0500
commit681349db67bb828ab926b53734b44c50249d5f65 (patch)
treeba164fba3f86eca2576850b4aa3a882e9f2d2c7b /app/database.py
parente035041e1a02332694bfa692f62217e58d9fada6 (diff)
downloadStrengthy-681349db67bb828ab926b53734b44c50249d5f65.tar.xz
Strengthy-681349db67bb828ab926b53734b44c50249d5f65.zip
Setup basic database connections
Diffstat (limited to 'app/database.py')
-rw-r--r--app/database.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/database.py b/app/database.py
new file mode 100644
index 0000000..e23aa5d
--- /dev/null
+++ b/app/database.py
@@ -0,0 +1,19 @@
+import sqlite3
+from app import app
+from flask import g
+
+# constants
+DATABASE_FILE = "../strengthy.db"
+
+# Called when an "appcontext" is closed, usually a request is finished
+@app.teardown_appcontext
+def close_db_conn(exception):
+ db = getattr(g, '_database', None)
+ if db is not None:
+ db.close()
+
+def database_get():
+ db = getattr(g, '_database', None)
+ if db is None:
+ db = g._database = sqlite3.connect(DATABASE_FILE)
+ return db