mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 17:08:35 +08:00
fix db config
This commit is contained in:
+5
-5
@@ -101,8 +101,10 @@ class ConfigModel(BaseModel):
|
|||||||
DB_TYPE: str = "sqlite"
|
DB_TYPE: str = "sqlite"
|
||||||
# 是否在控制台输出 SQL 语句,默认关闭
|
# 是否在控制台输出 SQL 语句,默认关闭
|
||||||
DB_ECHO: bool = False
|
DB_ECHO: bool = False
|
||||||
# SQLite 的 busy_timeout 参数,默认为 60 秒
|
# 数据库连接超时时间(秒),默认为 60 秒
|
||||||
DB_TIMEOUT: int = 60
|
DB_TIMEOUT: int = 60
|
||||||
|
# 是否启用 WAL 模式,仅适用于SQLite,默认开启
|
||||||
|
DB_WAL_ENABLE: bool = True
|
||||||
# 数据库连接池类型,QueuePool, NullPool
|
# 数据库连接池类型,QueuePool, NullPool
|
||||||
DB_POOL_TYPE: str = "QueuePool"
|
DB_POOL_TYPE: str = "QueuePool"
|
||||||
# 是否在获取连接时进行预先 ping 操作
|
# 是否在获取连接时进行预先 ping 操作
|
||||||
@@ -112,11 +114,9 @@ class ConfigModel(BaseModel):
|
|||||||
# 数据库连接池获取连接的超时时间(秒)
|
# 数据库连接池获取连接的超时时间(秒)
|
||||||
DB_POOL_TIMEOUT: int = 30
|
DB_POOL_TIMEOUT: int = 30
|
||||||
# SQLite 连接池大小
|
# SQLite 连接池大小
|
||||||
DB_POOL_SIZE: int = 30
|
DB_SQLITE_POOL_SIZE: int = 30
|
||||||
# SQLite 连接池溢出数量
|
# SQLite 连接池溢出数量
|
||||||
DB_MAX_OVERFLOW: int = 50
|
DB_SQLITE_MAX_OVERFLOW: int = 50
|
||||||
# SQLite 是否启用 WAL 模式,默认开启
|
|
||||||
DB_WAL_ENABLE: bool = True
|
|
||||||
# PostgreSQL 主机地址
|
# PostgreSQL 主机地址
|
||||||
DB_POSTGRESQL_HOST: str = "localhost"
|
DB_POSTGRESQL_HOST: str = "localhost"
|
||||||
# PostgreSQL 端口
|
# PostgreSQL 端口
|
||||||
|
|||||||
+10
-2
@@ -64,9 +64,9 @@ def _get_sqlite_engine(is_async: bool = False):
|
|||||||
# 当使用 QueuePool 时,添加 QueuePool 特有的参数
|
# 当使用 QueuePool 时,添加 QueuePool 特有的参数
|
||||||
if _pool_class == QueuePool:
|
if _pool_class == QueuePool:
|
||||||
_db_kwargs.update({
|
_db_kwargs.update({
|
||||||
"pool_size": settings.DB_POOL_SIZE,
|
"pool_size": settings.DB_SQLITE_POOL_SIZE,
|
||||||
"pool_timeout": settings.DB_POOL_TIMEOUT,
|
"pool_timeout": settings.DB_POOL_TIMEOUT,
|
||||||
"max_overflow": settings.DB_MAX_OVERFLOW
|
"max_overflow": settings.DB_SQLITE_MAX_OVERFLOW
|
||||||
})
|
})
|
||||||
|
|
||||||
# 创建数据库引擎
|
# 创建数据库引擎
|
||||||
@@ -122,6 +122,12 @@ def _get_postgresql_engine(is_async: bool = False):
|
|||||||
else:
|
else:
|
||||||
db_url = f"postgresql://{settings.DB_POSTGRESQL_USERNAME}@{settings.DB_POSTGRESQL_HOST}:{settings.DB_POSTGRESQL_PORT}/{settings.DB_POSTGRESQL_DATABASE}"
|
db_url = f"postgresql://{settings.DB_POSTGRESQL_USERNAME}@{settings.DB_POSTGRESQL_HOST}:{settings.DB_POSTGRESQL_PORT}/{settings.DB_POSTGRESQL_DATABASE}"
|
||||||
|
|
||||||
|
# PostgreSQL连接参数
|
||||||
|
_connect_args = {
|
||||||
|
"connect_timeout": settings.DB_TIMEOUT,
|
||||||
|
"command_timeout": settings.DB_TIMEOUT,
|
||||||
|
}
|
||||||
|
|
||||||
# 创建同步引擎
|
# 创建同步引擎
|
||||||
if not is_async:
|
if not is_async:
|
||||||
# 根据池类型设置 poolclass 和相关参数
|
# 根据池类型设置 poolclass 和相关参数
|
||||||
@@ -134,6 +140,7 @@ def _get_postgresql_engine(is_async: bool = False):
|
|||||||
"echo": settings.DB_ECHO,
|
"echo": settings.DB_ECHO,
|
||||||
"poolclass": _pool_class,
|
"poolclass": _pool_class,
|
||||||
"pool_recycle": settings.DB_POOL_RECYCLE,
|
"pool_recycle": settings.DB_POOL_RECYCLE,
|
||||||
|
"connect_args": _connect_args
|
||||||
}
|
}
|
||||||
|
|
||||||
# 当使用 QueuePool 时,添加 QueuePool 特有的参数
|
# 当使用 QueuePool 时,添加 QueuePool 特有的参数
|
||||||
@@ -160,6 +167,7 @@ def _get_postgresql_engine(is_async: bool = False):
|
|||||||
"echo": settings.DB_ECHO,
|
"echo": settings.DB_ECHO,
|
||||||
"poolclass": NullPool,
|
"poolclass": NullPool,
|
||||||
"pool_recycle": settings.DB_POOL_RECYCLE,
|
"pool_recycle": settings.DB_POOL_RECYCLE,
|
||||||
|
"connect_args": _connect_args
|
||||||
}
|
}
|
||||||
# 创建异步数据库引擎
|
# 创建异步数据库引擎
|
||||||
async_engine = create_async_engine(**_db_kwargs)
|
async_engine = create_async_engine(**_db_kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user