From 95bb027b933fd565690692c9a1f3bf0e0f040f0d Mon Sep 17 00:00:00 2001 From: Namya LG <53875297+Namyalg@users.noreply.github.com> Date: Mon, 5 Sep 2022 20:32:58 +0530 Subject: [PATCH] feat: endpoint to rename a table (#175) --- local/rest_api_gcbm/app.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/local/rest_api_gcbm/app.py b/local/rest_api_gcbm/app.py index 7184d3d7..0bb104ef 100644 --- a/local/rest_api_gcbm/app.py +++ b/local/rest_api_gcbm/app.py @@ -629,6 +629,36 @@ def send_table(): resp[table_name[0]] = schema return resp, 200 +@app.route("/gcbm/table/rename", methods=['POST']) +def rename_table(): + """ + Rename a table + --- + tags: + - gcbm + responses: + 200: + parameters: + - in: Params + name: title + type: string + name: previous + type: string + nsme: new + type: string + description: Status indicating success/failure in performing the rename + """ + title = request.form.get("title") or "simulation" + input_dir = f"{os.getcwd()}/input/{title}/db/" + try: + connection = sqlite3.connect(input_dir + "gcbm_input.db") + cursor = connection.cursor() + previous_name = request.form.get('previous') + new_name = request.form.get('new') + cursor.execute(f"ALTER TABLE {previous_name} rename to {new_name}") + return {"status": 1} + except Exception as exception: + return {"status": 0, "error": str(exception)} @app.route("/gcbm/dynamic", methods=["POST"]) def gcbm_dynamic():