feat: 配置文件新增数据库连接池相关配置
This commit is contained in:
@@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot'
|
|||||||
DB_DATABASE = 'ruoyi-fastapi'
|
DB_DATABASE = 'ruoyi-fastapi'
|
||||||
# 是否开启sqlalchemy日志
|
# 是否开启sqlalchemy日志
|
||||||
DB_ECHO = true
|
DB_ECHO = true
|
||||||
|
# 允许溢出连接池大小的最大连接数
|
||||||
|
DB_MAX_OVERFLOW = 10
|
||||||
|
# 连接池大小,0表示连接数无限制
|
||||||
|
DB_POOL_SIZE = 50
|
||||||
|
# 连接回收时间(单位:秒)
|
||||||
|
DB_POOL_RECYCLE = 3600
|
||||||
|
# 连接池中没有线程可用时,最多等待的时间(单位:秒)
|
||||||
|
DB_POOL_TIMEOUT = 30
|
||||||
|
|
||||||
# -------- Redis配置 --------
|
# -------- Redis配置 --------
|
||||||
# Redis主机
|
# Redis主机
|
||||||
|
@@ -42,6 +42,14 @@ DB_PASSWORD = 'root'
|
|||||||
DB_DATABASE = 'ruoyi-fastapi'
|
DB_DATABASE = 'ruoyi-fastapi'
|
||||||
# 是否开启sqlalchemy日志
|
# 是否开启sqlalchemy日志
|
||||||
DB_ECHO = true
|
DB_ECHO = true
|
||||||
|
# 允许溢出连接池大小的最大连接数
|
||||||
|
DB_MAX_OVERFLOW = 10
|
||||||
|
# 连接池大小,0表示连接数无限制
|
||||||
|
DB_POOL_SIZE = 50
|
||||||
|
# 连接回收时间(单位:秒)
|
||||||
|
DB_POOL_RECYCLE = 3600
|
||||||
|
# 连接池中没有线程可用时,最多等待的时间(单位:秒)
|
||||||
|
DB_POOL_TIMEOUT = 30
|
||||||
|
|
||||||
# -------- Redis配置 --------
|
# -------- Redis配置 --------
|
||||||
# Redis主机
|
# Redis主机
|
||||||
|
@@ -8,7 +8,12 @@ SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DataBaseConfig.db_username}:{quote_
|
|||||||
f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}"
|
f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}"
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
SQLALCHEMY_DATABASE_URL, echo=DataBaseConfig.db_echo
|
SQLALCHEMY_DATABASE_URL,
|
||||||
|
echo=DataBaseConfig.db_echo,
|
||||||
|
max_overflow=DataBaseConfig.db_max_overflow,
|
||||||
|
pool_size=DataBaseConfig.db_pool_size,
|
||||||
|
pool_recycle=DataBaseConfig.db_pool_recycle,
|
||||||
|
pool_timeout=DataBaseConfig.db_pool_timeout
|
||||||
)
|
)
|
||||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
@@ -41,6 +41,10 @@ class DataBaseSettings(BaseSettings):
|
|||||||
db_password: str = 'mysqlroot'
|
db_password: str = 'mysqlroot'
|
||||||
db_database: str = 'ruoyi-fastapi'
|
db_database: str = 'ruoyi-fastapi'
|
||||||
db_echo: bool = True
|
db_echo: bool = True
|
||||||
|
db_max_overflow: int = 10
|
||||||
|
db_pool_size: int = 50
|
||||||
|
db_pool_recycle: int = 3600
|
||||||
|
db_pool_timeout: int = 30
|
||||||
|
|
||||||
|
|
||||||
class RedisSettings(BaseSettings):
|
class RedisSettings(BaseSettings):
|
||||||
|
Reference in New Issue
Block a user