Skip to content

Commit

Permalink
feat: add API to return table info
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavsk1077 committed Dec 15, 2021
1 parent a095c8f commit 5b26374
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chaos_genius/views/data_source_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,26 @@ def get_schema_views(datasource_id, schema_name):

return jsonify({"message":message, "status":status, "view_names":view_names})

@blueprint.route("/table-info",methods=["GET"])
def get_table_info():
status = ""
message = ""
table_info = {}
try:
data = request.get_json()
datasource_id = data["datasource_id"]
schema = data["schema"]
table_name = data["table_name"]
data_source_obj = DataSource.get_by_id(datasource_id)
if data_source_obj:
table_info["columns"] = data_source_obj.get_columns(table_name, schema)
table_info["primary_key"] = data_source_obj.get_primary_key(table_name, schema)
status = "success"
else:
status = "failure"
message = "Unable fetch datasource matching the provided id"
except Exception as e:
status = "failure"
message = "Error in fetching table info: {}".format(e)
table_info = {}
return jsonify({"table_info":table_info, "status":status, "message":message})

0 comments on commit 5b26374

Please sign in to comment.