forked from DYC4/farm-protector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbModule.py
35 lines (25 loc) · 965 Bytes
/
dbModule.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
import os
import pymysql
from dotenv import load_dotenv
load_dotenv()
class Database():
def __init__(self):
self.db = pymysql.connect(host = os.environ.get("DATABASE_HOST"),
port = int(os.environ.get("DATABASE_PORT")),
user = os.environ.get("DATABASE_USERNAME"),
passwd = os.environ.get("DATABASE_PASSWORD"),
db = os.environ.get("DATABASE_DATABASE"),
charset = 'utf8')
self.cursor = self.db.cursor(pymysql.cursors.DictCursor)
def execute(self, query, args={}):
self.cursor.execute(query, args)
def executeOne(self,query,args = {}):
self.cursor.execute(query,args)
row = self.cursor.fetchone()
return row
def executeALL(self,query,args = {}):
self.cursor.execute(query,args)
row = self.cursor.fetchall()
return row
def commit(self):
self.db.commit()