-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL.py
More file actions
50 lines (44 loc) · 1.27 KB
/
SQL.py
File metadata and controls
50 lines (44 loc) · 1.27 KB
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
50
from config import *
from db.getNosqlInfo import NoSQLTool
sql = Blueprint('sql', __name__)
@sql.route('/exec-sql', methods=['GET'])
def exec_sql():
try:
data = {}
data = request.args
print(data)
assert 'sql' in data, 'missing parameters sql!'
sql_string = (data['sql'])
db = mysql()
exec_result = db.sql_exec(sql_string)
str_json = exec_result.to_json(orient='records')
res = json.loads(str_json)
db.close()
resp = jsonify(res)
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except Exception as e:
print(e)
return get_error_resp(e)
@sql.route('/tables', methods=['GET'])
def get_tables():
try:
db = mysql()
res = list(db.get_tables())
resp = jsonify(res)
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except Exception as e:
print(e)
return get_error_resp(e)
@sql.route('/getTables', methods=['GET'])
def get_columns():
try:
db = NoSQLTool()
res = list(db.get_columns())
resp = jsonify(res)
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except Exception as e:
print(e)
return get_error_resp(e)