Сделал в боту функцию, когда человек вводит определенную информацию, то информация сохраняется в базе данных, вроде все работает, все сохраняется. Но в консоли ошибка
C:\Users\Bekzod\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\storage.py:199: FSMStorageWarning: You haven’t set any storage yet so no states and no data will be saved.
You can connect MemoryStorage for debug purposes or non-essential data.
await self.reset_state(chat=chat, user=user, with_data=True)
C:\Users\Bekzod\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\storage.py:199: FSMStorageWarning: You haven’t set any storage yet so no states and no data will be saved.
You can connect MemoryStorage for debug purposes or non-essential data.
await self.reset_state(chat=chat, user=user, with_data=True)
Вот сам код
import sqlite3
class Database:
def __init__(self, path_to_db="Sqlite/database.db"):
self.path_to_db = path_to_db
@property
def connection(self):
return sqlite3.connect(self.path_to_db)
def execute(self, sql: str, parameters: tuple = None, fetchone = False,
fetchall = False, commit = False):
if not parameters:
parameters = tuple()
connection = self.connection
connection.set_trace_callback(logger)
cursor = connection.cursor()
data = None
cursor.execute(sql, parameters)
if commit:
connection.commit()
if fetchone:
data = cursor.fetchone()
if fetchall:
data = cursor.fetchall()
connection.close()
return data
def create_table_users(self):
sql = """
CREATE TABLE Users (
id int NOT NULL,
name varchar(255) NOT NULL,
treshka int,
kasan int,
presents int,
vstrecha int,
podklich int
PRIMARY KEY (id)
);
"""
self.execute(sql, commit=True)
def add_user(self, id:int, name:str, treshka:int = None, kasan:int = None, presents:int = None, vstrecha:int = None, podklich:int = None):
sql = "INSERT INTO Users(id, name, treshka, kasan, presents, vstrecha, podklich) VALUES(?, ?, ?, ?, ?, ?, ?)"
parameters = (id, name, treshka, kasan, presents, vstrecha, podklich)
self.execute(sql, parameters=parameters, commit=True)
def select_all_users(self):
sql = "SELECT * FROM Users"
return self.execute(sql, fetchall=True)
@staticmethod
def format_args(sql, parameters=dict):
sql += " AND ".join([
f"{item} = ?" for item in parameters
])
print(sql)
return sql, tuple(parameters.values())
def select_user(self, **kwargs):
sql = "SELECT * FROM Users WHERE"
sql, parameters = self.format_args(sql, kwargs)
return self.execute(sql, parameters, fetchone=True)
def count_users(self):
return self.execute("SELECT COUNT(*) from Users", fetchone=True)
#def update_email(self, email, id):
# sql = "UPDATE Users SET email =? WHERE id=?"
# return self.execute(sql, parameters=(email, id), commit=True)
def update_treshka(self, treshka, id):
sql = "UPDATE Users SET treshka =? WHERE id=?"
return self.execute(sql, parameters=(treshka, id), commit=True)
def delete_user(self):
self.execute("DELETE FROM Users WHERE True")
def logger(statement):
print(f"""
_________________________________________
Executing:
{statement}
_________________________________________
""")