v0.2
This commit is contained in:
+5
-10
@@ -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(
|
||||
@@ -102,12 +97,12 @@ async def get_user_images(user_id: int, limit: int = 10) -> List[Dict[str, Any]]
|
||||
"""Получение истории обработанных изображений пользователя"""
|
||||
async with aiosqlite.connect(DATABASE_PATH) as db:
|
||||
db.row_factory = aiosqlite.Row
|
||||
cursor = await db.execute("""
|
||||
async with db.execute("""
|
||||
SELECT id, original_file_id, processed_file_id, prompt, status, created_at, completed_at
|
||||
FROM images
|
||||
WHERE user_id = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ?
|
||||
""", (user_id, limit))
|
||||
rows = await cursor.fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
""", (user_id, limit)) as cursor:
|
||||
rows = await cursor.fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
Reference in New Issue
Block a user