double code
This commit is contained in:
parent
b69bbe67bc
commit
05679409a5
1 changed files with 0 additions and 26 deletions
|
@ -29,29 +29,3 @@ class Connection:
|
|||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
ENGINE: Engine | None = None
|
||||
SESSION_LOCAL: sessionmaker | None = None
|
||||
|
||||
|
||||
def reconnect(engine: Engine) -> None:
|
||||
global ENGINE, SESSION_LOCAL
|
||||
|
||||
ENGINE = engine
|
||||
SESSION_LOCAL = sessionmaker(
|
||||
autocommit=False, autoflush=False, bind=engine,
|
||||
)
|
||||
ORMBaseModel.metadata.create_all(bind=engine)
|
||||
|
||||
|
||||
async def get() -> Generator[Session | None, None, None]:
|
||||
if SESSION_LOCAL is None:
|
||||
yield None
|
||||
|
||||
else:
|
||||
db = SESSION_LOCAL()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
|
Loading…
Reference in a new issue