From bb16256ecc43973a80d2971c040843bfe17bfb0f Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Mon, 19 Jan 2026 16:01:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=BF=D1=86=D0=B8=D1=8F=20autocommit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/database.py b/database.py index 79282a8..d271997 100644 --- a/database.py +++ b/database.py @@ -4,7 +4,7 @@ from typing import List, Union class BasicDatabase: def __init__(self, connection_string: str): - self.conn = connect(connection_string) + self.conn = connect(connection_string, autocommit=True) self.cursor = self.conn.cursor() def get_chats(self): @@ -17,16 +17,13 @@ class BasicDatabase: def add_chat(self, chat_id: int): self.cursor.execute("INSERT INTO chats (id) VALUES (?)", chat_id) - self.conn.commit() def chat_update(self, chat_id: int, **kwargs): self.cursor.execute("UPDATE chats SET " + ", ".join(f + " = ?" for f in kwargs) + " WHERE id = ?", list(kwargs.values()) + [chat_id]) - self.conn.commit() def chat_delete(self, chat_id: int): self.cursor.execute("DELETE FROM chats WHERE id = ?", chat_id) - self.conn.commit() def get_user(self, chat_id: int, user_id: int): self.cursor.execute("SELECT * FROM users WHERE chat_id = ? AND user_id = ?", chat_id, user_id) @@ -38,14 +35,12 @@ class BasicDatabase: def add_user(self, chat_id: int, user_id: int): self.cursor.execute("INSERT INTO users (chat_id, user_id) VALUES (?, ?)", chat_id, user_id) - self.conn.commit() def user_set_last_message(self, chat_id: int, user_id: int, last_message: int): self.user_update(chat_id, user_id, last_message=last_message) def user_increment_messages(self, chat_id: int, user_id: int): self.user_increment(chat_id, user_id, ['messages_today', 'messages_month']) - self.conn.commit() def user_increment_warnings(self, chat_id: int, user_id: int): self.user_increment(chat_id, user_id, ['warnings']) @@ -53,18 +48,13 @@ class BasicDatabase: def user_increment(self, chat_id: int, user_id: int, fields: List[str]): self.cursor.execute("UPDATE users SET " + ", ".join(f + " = " + f + " + 1" for f in fields) + " WHERE chat_id = ? AND user_id = ?", chat_id, user_id) - self.conn.commit() def user_update(self, chat_id: int, user_id: int, **kwargs): - sql = "UPDATE users SET " + ", ".join(f + " = ?" for f in kwargs) + " WHERE chat_id = ? AND user_id = ?" - args = [chat_id, user_id] + list(kwargs.values()) self.cursor.execute("UPDATE users SET " + ", ".join(f + " = ?" for f in kwargs) + " WHERE chat_id = ? AND user_id = ?", list(kwargs.values()) + [chat_id, user_id]) - self.conn.commit() def delete_user(self, chat_id: int, user_id: int): self.cursor.execute("DELETE FROM users WHERE chat_id = ? AND user_id = ?", chat_id, user_id) - self.conn.commit() def get_top_messages_today(self, chat_id: int): self.cursor.execute(""" @@ -104,17 +94,11 @@ class BasicDatabase: """, chat_id) return self._to_dict(self.cursor.fetchall()) - def delete_users(self, chat_id: int): - self.cursor.execute("DELETE FROM users WHERE chat_id = ?", chat_id) - self.conn.commit() - def reset_messages_today(self): self.cursor.execute("UPDATE users SET messages_today = 0") - self.conn.commit() def reset_messages_month(self): self.cursor.execute("UPDATE users SET messages_month = 0") - self.conn.commit() def create_chat_if_not_exists(self, chat_id: int): chat = self.get_chat(chat_id)