aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/auth/db.py')
-rw-r--r--gn3/auth/db.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gn3/auth/db.py b/gn3/auth/db.py
new file mode 100644
index 0000000..c0d0415
--- /dev/null
+++ b/gn3/auth/db.py
@@ -0,0 +1,19 @@
+"""Handle connection to auth database."""
+import sqlite3
+import contextlib
+
+@contextlib.contextmanager
+def connection(db_path: str):
+ connection = sqlite3.connect(db_path)
+ try:
+ yield connection
+ finally:
+ connection.close()
+
+@contextlib.contextmanager
+def cursor(connection):
+ cur = connection.cursor()
+ try:
+ yield cur
+ finally:
+ cur.close()