From 4638c5d021f76a339987c669972b8e75cce4899d Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Wed, 19 Oct 2022 11:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E5=9B=9E=E9=80=80=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/database/__init__.py | 161 +++++++++++++++--------------- 1 file changed, 81 insertions(+), 80 deletions(-) diff --git a/LittlePaimon/database/__init__.py b/LittlePaimon/database/__init__.py index 88c6b50..fe1b711 100644 --- a/LittlePaimon/database/__init__.py +++ b/LittlePaimon/database/__init__.py @@ -6,84 +6,84 @@ from nonebot.log import logger from LittlePaimon.config import GENSHIN_DB_PATH, SUB_DB_PATH, GENSHIN_VOICE_DB_PATH, MANAGER_DB_PATH, LEARNING_CHAT_DB_PATH -# DATABASE = { -# "connections": { -# "genshin": { -# "engine": "tortoise.backends.sqlite", -# "credentials": {"file_path": GENSHIN_DB_PATH}, -# }, -# "subscription": { -# "engine": "tortoise.backends.sqlite", -# "credentials": {"file_path": SUB_DB_PATH}, -# }, -# 'genshin_voice': { -# "engine": "tortoise.backends.sqlite", -# "credentials": {"file_path": GENSHIN_VOICE_DB_PATH}, -# }, -# 'manager': { -# "engine": "tortoise.backends.sqlite", -# "credentials": {"file_path": MANAGER_DB_PATH}, -# }, -# 'learning_chat': { -# "engine": "tortoise.backends.sqlite", -# "credentials": {"file_path": LEARNING_CHAT_DB_PATH}, -# }, +DATABASE = { + "connections": { + "genshin": { + "engine": "tortoise.backends.sqlite", + "credentials": {"file_path": GENSHIN_DB_PATH}, + }, + "subscription": { + "engine": "tortoise.backends.sqlite", + "credentials": {"file_path": SUB_DB_PATH}, + }, + 'genshin_voice': { + "engine": "tortoise.backends.sqlite", + "credentials": {"file_path": GENSHIN_VOICE_DB_PATH}, + }, + 'manager': { + "engine": "tortoise.backends.sqlite", + "credentials": {"file_path": MANAGER_DB_PATH}, + }, + 'learning_chat': { + "engine": "tortoise.backends.sqlite", + "credentials": {"file_path": LEARNING_CHAT_DB_PATH}, + }, + }, + "apps": { + "genshin": { + "models": ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'], + "default_connection": "genshin", + }, + "subscription": { + "models": ['LittlePaimon.database.models.subscription'], + "default_connection": "subscription", + }, + "genshin_voice": { + "models": ['LittlePaimon.database.models.genshin_voice'], + "default_connection": "genshin_voice", + }, + "manager": { + "models": ['LittlePaimon.database.models.manager'], + "default_connection": "manager", + }, + "learning_chat": { + "models": ['LittlePaimon.database.models.learning_chat'], + "default_connection": "learning_chat", + } + }, +} +# DATABASE = [ +# { +# 'db_url': f'sqlite://{GENSHIN_DB_PATH}', +# 'models': ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'], # }, -# "apps": { -# "genshin": { -# "models": ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'], -# "default_connection": "genshin", -# }, -# "subscription": { -# "models": ['LittlePaimon.database.models.subscription'], -# "default_connection": "subscription", -# }, -# "genshin_voice": { -# "models": ['LittlePaimon.database.models.genshin_voice'], -# "default_connection": "genshin_voice", -# }, -# "manager": { -# "models": ['LittlePaimon.database.models.manager'], -# "default_connection": "manager", -# }, -# "learning_chat": { -# "models": ['LittlePaimon.database.models.learning_chat'], -# "default_connection": "learning_chat", -# } +# { +# 'db_url': f'sqlite://{SUB_DB_PATH}', +# 'models': ['LittlePaimon.database.models.subscription'], # }, -# } -DATABASE = [ - { - 'db_url': f'sqlite://{GENSHIN_DB_PATH}', - 'models': ['LittlePaimon.database.models.player_info', 'LittlePaimon.database.models.abyss_info', 'LittlePaimon.database.models.character', 'LittlePaimon.database.models.cookie'], - }, - { - 'db_url': f'sqlite://{SUB_DB_PATH}', - 'models': ['LittlePaimon.database.models.subscription'], - }, - { - 'db_url': f'sqlite://{GENSHIN_VOICE_DB_PATH}', - 'models': ['LittlePaimon.database.models.genshin_voice'], - }, - { - 'db_url': f'sqlite://{MANAGER_DB_PATH}', - 'models': ['LittlePaimon.database.models.manager'], - }, - { - 'db_url': f'sqlite://{LEARNING_CHAT_DB_PATH}', - 'models': ['LittlePaimon.database.models.learning_chat'], - }, -] +# { +# 'db_url': f'sqlite://{GENSHIN_VOICE_DB_PATH}', +# 'models': ['LittlePaimon.database.models.genshin_voice'], +# }, +# { +# 'db_url': f'sqlite://{MANAGER_DB_PATH}', +# 'models': ['LittlePaimon.database.models.manager'], +# }, +# { +# 'db_url': f'sqlite://{LEARNING_CHAT_DB_PATH}', +# 'models': ['LittlePaimon.database.models.learning_chat'], +# }, +# ] -def register_database(db_path: Optional[Union[str, Path]], models: List[Union[str, Path]]): - """ - 注册数据库 - """ - DATABASE.append({ - 'db_url': f'sqlite://{db_path}', - 'models': models, - }) +# def register_database(db_path: Optional[Union[str, Path]], models: List[Union[str, Path]]): +# """ +# 注册数据库 +# """ +# DATABASE.append({ +# 'db_url': f'sqlite://{db_path}', +# 'models': models, +# }) async def connect(): @@ -91,12 +91,13 @@ async def connect(): 建立数据库连接 """ try: - for db in DATABASE: - await Tortoise.init( - db_url=db['db_url'], - modules={'models': db['models']}, - ) - await Tortoise.generate_schemas() + # for db in DATABASE: + # await Tortoise.init( + # db_url=db['db_url'], + # modules={'models': db['models']}, + # ) + await Tortoise.init(DATABASE) + await Tortoise.generate_schemas() logger.opt(colors=True).success("[数据库]连接成功") except Exception as e: logger.opt(colors=True).warning(f"[数据库]连接失败:{e}")