-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
72 lines (64 loc) · 2.26 KB
/
database.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sqlite3
class SQLiteDBManager:
def __init__(self, db_path):
self.db_path = db_path
self._create_table()
def _connect(self):
return sqlite3.connect(self.db_path)
def _create_table(self):
conn = self._connect()
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS orders (
uniqid TEXT PRIMARY KEY,
chat_id INTEGER,
user_id INTEGER,
username TEXT,
status TEXT,
crypto TEXT,
amount INTEGER,
plan TEXT,
hash TEXT
)
''')
conn.commit()
conn.close()
def insert_order(self, chat_id, user_id, username, uniqid, status, crypto, usdvalue, selected_plan,hash):
conn = self._connect()
cursor = conn.cursor()
cursor.execute('''
INSERT INTO orders (chat_id, user_id, username, uniqid, status, crypto, amount, plan, hash)
VALUES (?, ?, ?, ?, ?, ?, ?, ? ,?)
''', (chat_id, user_id, username, uniqid, status, crypto,usdvalue,selected_plan, hash))
conn.commit()
conn.close()
def update_order_status(self, uniqid, new_status):
conn = self._connect()
cursor = conn.cursor()
cursor.execute('''
UPDATE orders SET status = ? WHERE uniqid = ?
''', (new_status, uniqid))
conn.commit()
conn.close()
def get_order_status(self, uniqid):
conn = self._connect()
cursor = conn.cursor()
cursor.execute('SELECT status FROM orders WHERE uniqid = ?', (uniqid,))
status = cursor.fetchone()
conn.close()
return status[0] if status else None
def get_order_details(self, uniqid):
conn = self._connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM orders WHERE uniqid = ?', (uniqid,))
details = cursor.fetchone()
conn.close()
return details
def update_order_hash(self, uniqid, crypto_hash):
conn = self._connect()
cursor = conn.cursor()
cursor.execute('''
UPDATE orders SET hash = ? WHERE uniqid = ?
''', (crypto_hash, uniqid))
conn.commit()
conn.close()