MAJOR: Reworked database to be easier to use and close automatically to prevent resource leaks

This commit is contained in:
JustIceO7
2025-01-29 17:47:29 +00:00
parent 83b458ed99
commit dfdbe4a7d4
9 changed files with 181 additions and 209 deletions

View File

@@ -6,6 +6,15 @@ class Database:
self._db = os.path.join(os.path.abspath(os.path.dirname(__file__)), "app.db")
self._conn = None
self.cursor = None
self.create_connection()
def __enter__(self):
"""Returns db on using with clause"""
return self
def __exit__(self, exc_type, exc_value, traceback):
"""Closes db connection after with clause"""
self.close_connection()
def create_connection(self) -> None:
"""Create a database connection if not already established."""