feat: add create and change profile

This commit is contained in:
Faynot
2026-03-28 21:39:27 +03:00
parent 6d2b4b6346
commit 1db524f757
2 changed files with 135 additions and 31 deletions

View File

@@ -9,7 +9,10 @@ class Database:
await db.execute("""
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
user_id INTEGER UNIQUE
user_id INTEGER UNIQUE,
sphere TEXT,
language TEXT,
preferences TEXT
)
""")
await db.commit()
@@ -22,8 +25,22 @@ class Database:
)
await db.commit()
async def update_user_data(self, user_id: int, data: dict):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"UPDATE users SET sphere = ?, language = ?, preferences = ? WHERE user_id = ?",
(data.get('sphere'), data.get('language'), data.get('preferences'), user_id)
)
await db.commit()
async def get_all(self):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute("SELECT * FROM users") as cursor:
rows = await cursor.fetchall()
return rows
return await cursor.fetchall()
async def get_user(self, user_id: int):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT sphere, language, preferences FROM users WHERE user_id = ?",
(user_id,)
) as cursor:
return await cursor.fetchone()