mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
document + rename stuff
This commit is contained in:
+26
-1
@@ -1,5 +1,30 @@
|
||||
from contextlib import contextmanager
|
||||
from sqlalchemy import Engine
|
||||
|
||||
|
||||
class DbEngine:
|
||||
engine: Engine = None
|
||||
"""
|
||||
The database engine instance.
|
||||
"""
|
||||
|
||||
engine: Engine
|
||||
|
||||
@classmethod
|
||||
@contextmanager
|
||||
def manager(cls, commit: bool):
|
||||
"""
|
||||
This context manager manages access to the database.
|
||||
|
||||
When the context manager is entered, it returns a connection object that can be used to execute SQL statements.
|
||||
|
||||
If the `commit` parameter is set to `True`, the context manager will commit the transaction when it exits.
|
||||
"""
|
||||
|
||||
try:
|
||||
conn = cls.engine.connect()
|
||||
yield conn.execution_options(preserve_rowcount=True)
|
||||
|
||||
if commit:
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user