forked from preethu08052k/testapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
28 lines (26 loc) · 866 Bytes
/
Copy pathdb.py
File metadata and controls
28 lines (26 loc) · 866 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
from flask import jsonify
from decimal import Decimal
import pymysql
def query(querystr,return_json=True):
connection=pymysql.connect( host='cosc-skillup.cxgok3weok8n.ap-south-1.rds.amazonaws.com',
user='admin',
password='coscskillup',
db='testapi',
cursorclass=pymysql.cursors.DictCursor )
connection.begin()
cursor=connection.cursor()
cursor.execute(querystr)
result=encode(cursor.fetchall())
connection.commit()
cursor.close()
connection.close()
if return_json:
return jsonify(result)
else:
return result
def encode(data):
for row in data:
for key,value in row.items():
if isinstance(value,Decimal):
row[key]=str(value)
return data