From b2db8b857439994607e09e342d9d7dd93bd0a14f Mon Sep 17 00:00:00 2001 From: adk23333 <2633103794@qq.com> Date: Tue, 19 Dec 2023 02:49:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0config=E6=96=87=E4=BB=B6,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0orm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model.py | 1 + server.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/model.py b/model.py index 9f4d8ae..7c14479 100644 --- a/model.py +++ b/model.py @@ -60,6 +60,7 @@ class SioConfig(BaseModel): client_id: str client_secret: str localhost: str + db_url: str @dataclass diff --git a/server.py b/server.py index 9bfb228..55a87f1 100644 --- a/server.py +++ b/server.py @@ -6,6 +6,7 @@ from sanic import Sanic, Request from sanic.log import logger, Colors from sanic.response import text from socketio import AsyncClient +from tortoise.contrib.sanic import register_tortoise from command import command_convert from gitea_model import WebHookIssueComment, WebHookIssue, GiteaEvent @@ -21,9 +22,16 @@ def get_config() -> SioConfig: return SioConfig(**config) +SIO_CONFIG = get_config() + +register_tortoise( + app, db_url=SIO_CONFIG.db_url, modules={"models": ["orm"]}, generate_schemas=True +) + + @app.before_server_start async def setup_before_start(_app): - _app.ctx.sio_config = get_config() + _app.ctx.sio_config = SIO_CONFIG _app.ctx.sio = AsyncClient() start_sio_listener()