Skip to content

Commit

Permalink
feat: endpoint to rename a table (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Namyalg authored Sep 5, 2022
1 parent 3a4ea03 commit 95bb027
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions local/rest_api_gcbm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 95bb027

Please sign in to comment.