[REFORMAT] Ran black reformat
This commit is contained in:
@@ -10,6 +10,7 @@ Base = declarative_base() # Used for models
|
||||
_engine = None
|
||||
_SessionLocal = None
|
||||
|
||||
|
||||
def get_engine():
|
||||
global _engine
|
||||
if _engine is None:
|
||||
@@ -20,10 +21,13 @@ def get_engine():
|
||||
try:
|
||||
_engine.connect()
|
||||
except Exception:
|
||||
raise Exception("Database connection failed. Is the database server running?")
|
||||
raise Exception(
|
||||
"Database connection failed. Is the database server running?"
|
||||
)
|
||||
Base.metadata.create_all(_engine) # Create tables here
|
||||
return _engine
|
||||
|
||||
|
||||
def get_sessionmaker():
|
||||
global _SessionLocal
|
||||
if _SessionLocal is None:
|
||||
@@ -31,10 +35,11 @@ def get_sessionmaker():
|
||||
_SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
return _SessionLocal
|
||||
|
||||
|
||||
def get_db() -> Generator[Session, None, None]:
|
||||
SessionLocal = get_sessionmaker()
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user