This commit is contained in:
2026-05-08 20:56:12 +03:00
parent 34d89c2245
commit b748aeaabe
2 changed files with 548 additions and 146 deletions
+2 -6
View File
@@ -8,10 +8,8 @@ DATABASE_PATH = "bot_database.db"
async def init_db():
"""Инициализация базы данных и создание таблиц"""
async with aiosqlite.connect(DATABASE_PATH) as db:
# Включаем WAL режим для лучшей производительности
await db.execute("PRAGMA journal_mode=WAL;")
# Таблица пользователей
await db.execute("""
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY,
@@ -23,7 +21,6 @@ async def init_db():
)
""")
# Таблица обработанных изображений
await db.execute("""
CREATE TABLE IF NOT EXISTS images (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -71,11 +68,9 @@ async def save_image_record(
cursor = await db.execute("""
INSERT INTO images (user_id, original_file_id, original_url, prompt, created_at, status)
VALUES (?, ?, ?, ?, ?, 'processing')
RETURNING id
""", (user_id, original_file_id, original_url, prompt, now))
await db.commit()
row = await cursor.fetchone()
return row[0] if row else None
return cursor.lastrowid
async def update_image_record(
@@ -110,4 +105,5 @@ async def get_user_images(user_id: int, limit: int = 10) -> List[Dict[str, Any]]
LIMIT ?
""", (user_id, limit))
rows = await cursor.fetchall()
await db.commit()
return [dict(row) for row in rows]