From 75a8c49373d7714842759740516605af9d03527b Mon Sep 17 00:00:00 2001 From: Jonathan Lucas Date: Sun, 18 Aug 2024 18:40:29 -0500 Subject: [PATCH] Removed database repository --- database.py | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 database.py diff --git a/database.py b/database.py deleted file mode 100644 index 5429bee..0000000 --- a/database.py +++ /dev/null @@ -1,42 +0,0 @@ -import sqlite3 -import json -from typing import List, Dict, Any - -class Database: - def __init__(self, db_file='telegram_bot.db'): - self.db_file = db_file - self.conn = sqlite3.connect(self.db_file) - self.create_tables() - - def create_tables(self): - with self.conn: - self.conn.execute(''' - CREATE TABLE IF NOT EXISTS conversations ( - user_id INTEGER PRIMARY KEY, - history TEXT - ) - ''') - - def save_conversation(self, user_id: int, history: List[Dict[str, Any]]): - with self.conn: - self.conn.execute(''' - INSERT OR REPLACE INTO conversations (user_id, history) - VALUES (?, ?) - ''', (user_id, json.dumps(history))) - - def get_conversation(self, user_id: int) -> List[Dict[str, Any]]: - cursor = self.conn.execute('SELECT history FROM conversations WHERE user_id = ?', (user_id,)) - result = cursor.fetchone() - if result: - return json.loads(result[0]) - return [] - - def clear_conversation(self, user_id: int): - with self.conn: - self.conn.execute('DELETE FROM conversations WHERE user_id = ?', (user_id,)) - - def close(self): - self.conn.close() - -# Create a global instance of the Database class -db = Database() \ No newline at end of file