-
Notifications
You must be signed in to change notification settings - Fork 1
/
sss_db.py
47 lines (31 loc) · 1.03 KB
/
sss_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
import mysql.connector as mdb
from sss_config import *
def connectToDB():
return mdb.connect(**configDB)
def writeDB(name, pos, description, date, url):
DBconn = connectToDB()
queryCurs = DBconn.cursor()
queryCurs.execute(
'INSERT INTO Manifesto (name, pos, description, date, url) VALUES (%s, %s, %s, %s, %s)', (name, pos, description, date, url ))
DBconn.commit()
def readDB(name):
DBconn = connectToDB()
queryCurs = DBconn.cursor(dictionary=True)
queryCurs.execute(
'SELECT name, pos, description, date, url '
'FROM Manifesto '
'WHERE name LIKE %s; ', (name,))
row = queryCurs.fetchall()
row_json = [dict(rec) for rec in row]
DBconn.close()
return row_json
def readDB_all():
DBconn = connectToDB()
queryCurs = DBconn.cursor(dictionary=True)
queryCurs.execute(
'SELECT name, pos, description, date, url '
'FROM Manifesto; ')
row = queryCurs.fetchall()
row_json = [dict(rec) for rec in row]
DBconn.close()
return row_json