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.
28 lines
572 B
28 lines
572 B
1 month ago
|
from config.database import *
|
||
|
from utils.log_util import logger
|
||
|
|
||
|
|
||
|
def get_db_pro():
|
||
|
"""
|
||
|
每一个请求处理完毕后会关闭当前连接,不同的请求使用不同的连接
|
||
|
:return:
|
||
|
"""
|
||
|
current_db = SessionLocal()
|
||
|
try:
|
||
|
yield current_db
|
||
|
finally:
|
||
|
current_db.close()
|
||
|
|
||
|
|
||
|
async def init_create_table():
|
||
|
"""
|
||
|
应用启动时初始化数据库连接
|
||
|
:return:
|
||
|
"""
|
||
|
logger.info("初始化数据库连接...")
|
||
|
Base.metadata.create_all(bind=engine)
|
||
|
logger.info("数据库连接成功")
|
||
|
|
||
|
|
||
|
get_db = get_db_pro
|