feat: bot start, database

This commit is contained in:
Faynot
2026-03-28 20:59:54 +03:00
parent b52990acc6
commit 6d2b4b6346
4 changed files with 71 additions and 30 deletions

29
database.py Normal file
View File

@@ -0,0 +1,29 @@
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