Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytz
from py_tools.connections.db.mysql import DBManager, BaseOrmTable, SQLAlchemyManager
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine

from bot.bot_client import BotClient
Expand All @@ -19,15 +18,15 @@

async def create_database_if_not_exists() -> None:
"""创建数据库。"""
engine_without_db = create_async_engine(
engine = create_async_engine(
f"mysql+asyncmy://{config.db_user}:{config.db_pass}@{config.db_host}:{config.db_port}/",
echo=True,
)
async with engine_without_db.begin() as conn:
async with engine.begin() as conn:
query = f"CREATE DATABASE IF NOT EXISTS {config.db_name}"
logger.info(f"SQL Query: {query}, Context: Creating database")
await conn.execute(text(query))
await engine_without_db.dispose()
await conn.exec_driver_sql(query)
await engine.dispose()


async def _init_db() -> None:
Expand Down
Loading