-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
49 lines (39 loc) · 1.31 KB
/
db.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
from config import singleton
import mysql.connector
@singleton
class Db():
def __init__(self):
self.config = {
'user': 'root',
'password': '123456',
'host': 'localhost',
'database': 'currency_exchange',
'raise_on_warnings': True,
'use_pure': False
}
def queryInsert(self, queryToExecute, params):
self.cnx = mysql.connector.connect(**self.config)
self.cursor = self.cnx.cursor();
self.cursor.execute(queryToExecute, params)
self.cnx.commit()
self.cursor.close()
self.cnx.close()
def querySelect(self, queryToExecute):
self.cnx = mysql.connector.connect(**self.config)
self.cursor = self.cnx.cursor();
self.cursor.execute(queryToExecute)
items = self.cursor.fetchall()
self.cursor.close()
self.cnx.close()
return items
def querySelectOne(self, queryToExecute):
self.cnx = mysql.connector.connect(**self.config)
self.cursor = self.cnx.cursor();
self.cursor.execute(queryToExecute)
selected = self.cursor.fetchone()
self.cursor.close()
self.cnx.close()
if selected is None:
return False
else:
return selected