ClanStat/app/db.py

37 lines
877 B
Python
Raw Normal View History

2024-11-27 02:58:28 +03:00
# Импорт модулей стандартной библиотеки
import sqlite3
import json
class DataBase(object):
"""..."""
def __init__(self, path):
super(DataBase, self).__init__()
self.path = path
def connect(self) -> bool:
self.conn = sqlite3.connect(self.path)
return True
def close(self) -> bool:
self.conn.close()
return True
def commit(self) -> None:
self.conn.commit()
return True
def add_data(self, data, wins: bool) -> bool: # wins изменит на Enum
if wins:
table = 'wins'
else:
table = 'donates'
cur = self.conn.cursor()
cur.execute('INSERT INTO {table} (\'data\') VALUES (\'{data}\')'.format(table=table, data=json.dumps(data)))
self.commit()
cur.close()
return True