Тестовый SQLite.

This commit is contained in:
WowInceptionGood
2026-03-08 21:12:57 +00:00
parent de07725212
commit bcba51ac5d
7 changed files with 38 additions and 16 deletions

View File

@@ -20,6 +20,9 @@ class ServerConfig:
### Уровень отладки
log_level = os.getenv("log_level") or "debug"
### Тип базы данных
db_type = os.getenv("db_type") or "mysql"
### MySQL
db_host = os.getenv("db_host") or "127.0.0.1"
db_port = int(os.getenv("db_port") or 3306)
@@ -27,6 +30,9 @@ class ServerConfig:
db_password = os.getenv("db_password") or "qwerty"
db_name = os.getenv("db_name") or "openmax"
### SQLite
db_file = os.getenv("db_file") or "openmax.db"
### SSL
certfile = os.getenv("certfile") or "cert.pem"
keyfile = os.getenv("keyfile") or "key.pem"

View File

@@ -1,5 +1,5 @@
# Импортирование библиотек
import aiomysql, ssl, logging, asyncio
import ssl, logging, asyncio
from common.config import ServerConfig
from oneme_tcp.controller import OnemeMobileController
from telegrambot.controller import TelegramBotController
@@ -10,16 +10,24 @@ server_config = ServerConfig()
async def init_db():
"""Инициализация базы данных"""
# Создаем пул
db = await aiomysql.create_pool(
host=server_config.db_host,
port=server_config.db_port,
user=server_config.db_user,
password=server_config.db_password,
db=server_config.db_name,
cursorclass=aiomysql.DictCursor,
autocommit=True
)
db = {}
if server_config.db_type == "mysql":
import aiomysql
db = await aiomysql.create_pool(
host=server_config.db_host,
port=server_config.db_port,
user=server_config.db_user,
password=server_config.db_password,
db=server_config.db_name,
cursorclass=aiomysql.DictCursor,
autocommit=True
)
elif server_config.db_type == "sqlite":
import aiosqlite
raw_db = await aiosqlite.connect(server_config.db_file)
db["acquire"] = raw_db
# Возвращаем
return db