-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdbModule.py
More file actions
31 lines (25 loc) · 921 Bytes
/
dbModule.py
File metadata and controls
31 lines (25 loc) · 921 Bytes
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
import pymysql
from dotenv import load_dotenv
import os
# load .env
load_dotenv()
class Database():
def __init__(self):
self.db = pymysql.connect(host='database-2.cc5um8ekupdb.ap-northeast-2.rds.amazonaws.com',
user='admin',
password=os.environ.get('DATABASE_PW'),
db='LC',
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()