Files
qwork/database.py
2026-03-28 20:59:54 +03:00

30 lines
936 B
Python

import aiosqlite
class Database:
def __init__(self, db_path: str):
self.db_path = db_path
async def create_tables(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
user_id INTEGER UNIQUE
)
""")
await db.commit()
async def add_user(self, user_id: int):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"INSERT OR IGNORE INTO users (user_id) VALUES (?)",
(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