-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (55 loc) · 1.61 KB
/
main.py
File metadata and controls
66 lines (55 loc) · 1.61 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask import Flask, request, current_app
from RemoteDB.src.QueryExecutor import QueryExecutor
import json
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
resp = {
"success": True,
"message": "hello world",
"data": {},
}
return resp
@app.route("/execute-query", methods=["POST"])
def execute_query():
request_body = request.data
current_app.logger.error("request body: %s", request_body)
if not request_body:
return (
{
"success": False,
"message": "Invalid request body",
"data": {}
},
400,
)
data = request_body.decode('utf-8')
query = json.loads(data)
query_executor = QueryExecutor()
if query[0] == "COMMIT":
result = query_executor.comitChanges(query)
elif query[0] == "RELEASE":
result = query_executor.releaseLock(query)
else:
result = query_executor.processQuery(query)
current_app.logger.error("query result: %s", result)
return {
"success": True,
"message": "Query executed",
"data": result,
}
@app.route("/get-local-dictionary", methods=["GET"])
def get_local_dictionary():
file_data = None
with open("RemoteDB/src/Database/Dictionaries/LocalDataDictionary.json", 'r') as dd:
file_data = dd.read()
json_data = dict()
if file_data:
json_data = json.loads(file_data)
return {
"success": True,
"message": "Local data dictionary",
"data": json_data
}
if __name__ == "__main__":
app.run(host="0.0.0.0")