feat: add create and change profile
This commit is contained in:
23
database.py
23
database.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user