-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.py
49 lines (41 loc) · 1.31 KB
/
handler.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
48
49
import json
from query_handler import connect, query_handler
"""
Message type:
0: Check Connection
1: Visualize Query Execution Plan; Input: Query
2: Input: Plan
"""
defaultDBData = {
"db_name" : "CZ4031",
"user" : "postgres",
"password" : "postgres",
"host" : "localhost",
"port" : "5432"
}
def handler(payload):
action_type = payload["type"]
data = payload["data"]
if action_type == 0:
result = connect(data)
if result:
defaultDBData["db_name"] = data["db_name"]
defaultDBData["user"] = data["user"]
defaultDBData["password"] = data["password"]
defaultDBData["host"] = data["host"]
defaultDBData["port"] = data["port"]
return "Connection Successful!"
else:
return "Unable to establish connection to the database, Please check your credentials!"
elif action_type == 1:
data["db_name"] = defaultDBData["db_name"]
data["user"] = defaultDBData["user"]
data["password"] = defaultDBData["password"]
data["host"] = defaultDBData["host"]
data["port"] = defaultDBData["port"]
result = query_handler(data)
return result
elif action_type == 2:
return data["plan"]
else:
print("Type not valid")