-
Notifications
You must be signed in to change notification settings - Fork 1
/
spent.py
43 lines (38 loc) · 1.3 KB
/
spent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import _sqlite3 as db
class Transaction():
def __init__(self):
'''
Инициализируем новую базу данных для хранения транзакций
'''
self.conn = db.connect('transaction.db')
self.cursor = self.conn.cursor()
sql_query = '''
create table if not exists expenses(
transaction_id integer primary key,
user_id integer,
amount number,
category string,
date string,
message string
)
'''
self.cursor.execute(sql_query)
# сохраняем изменения
self.conn.commit()
def delete_users(self):
# удаляет всю базу данных
self.conn = db.connect('transaction.db')
self.cursor = self.conn.cursor()
sql_query = '''
delete from expenses
'''
self.cursor.execute(sql_query)
self.conn.commit()
def delete_transaction(self, id):
self.conn = db.connect('transaction.db')
self.cursor = self.conn.cursor()
sql_query = '''
delete from expenses where id = ?
'''
self.cursor.execute(sql_query)
self.conn.commit()