You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
680 B

# !/usr/bin/env python3
# -*- encoding : utf-8 -*-
# @Filename : session.py
# @Software : VSCode
# @Datetime : 2021/11/04 15:49:56
# @Author : leo liu
# @Version : 1.0
# @Description :
from typing import Generator
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from core.settings import config
engine = create_engine(
config.SQLALCHEMY_DATABASE_URI
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db() -> Generator:
try:
db = SessionLocal()
yield db
finally:
db.close()