Skip to content

Commit b2ed3b5

Browse files
committed
Added get definition route
1 parent a7f54b0 commit b2ed3b5

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

dj_gui_api_server/DJConnector.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def list_tables(jwt_payload, schema_name):
9494
table_name (string): Table name under the given schema, must be in camel case
9595
9696
Returns:
97-
(tuples)
97+
list<tuples_as_dicts>: a list of tuples in dict form
9898
"""
9999
@staticmethod
100100
def fetch_tuples(jwt_payload, schema_name, table_name):
@@ -103,6 +103,24 @@ def fetch_tuples(jwt_payload, schema_name, table_name):
103103
schema_virtual_module = dj.create_virtual_module(schema_name, schema_name)
104104
return getattr(schema_virtual_module, table_name).fetch(as_dict=True)
105105

106+
"""
107+
Get the table definition
108+
109+
Parameters:
110+
jwt_payload (dict): Dictionary containing databaseAddress, username and password strings
111+
schema_name (string): Schema name where to find the table under
112+
table_name (string): Table name under the given schema, must be in camel case
113+
114+
Returns:
115+
string: definition of the table
116+
"""
117+
@staticmethod
118+
def get_table_definition(jwt_payload, schema_name, table_name):
119+
DJConnector.set_datajoint_config(jwt_payload)
120+
121+
schema_virtual_module = dj.create_virtual_module(schema_name, schema_name)
122+
return getattr(schema_virtual_module, table_name).describe()
123+
106124
"""
107125
Method to set credentials for database
108126
@@ -119,6 +137,7 @@ def set_datajoint_config(jwt_payload):
119137
dj.config['database.password'] = jwt_payload['password']
120138

121139
dj.conn(reset=True)
140+
122141
"""
123142
Helper method for converting snake to camel case
124143

dj_gui_api_server/DJGUIAPIServer.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def list_tables(jwt_payload):
114114
body: (html:POST:JSON): {"schemaName": <schema_name>, "tableName": <table_name>} (NOTE: Table name must be in CamalCase)
115115
116116
Returns:
117-
dict(tuples=[tuples_as_dicts])
117+
dict(table_definition=table_definition): table_definition will be in string format
118118
or
119119
dict(error=<error_message>): With error message of why it failed
120120
"""
@@ -127,5 +127,27 @@ def fetch_tuples(jwt_payload):
127127
except Exception as e:
128128
return str(e), 500
129129

130+
"""
131+
Route to get table definition
132+
133+
Parameters:
134+
header: (html:GET:Authorization): Must include in format of: bearer <JWT-Token>
135+
body: (html:POST:JSON): {"schemaName": <schema_name>, "tableName": <table_name>} (NOTE: Table name must be in CamalCase)
136+
137+
Returns:
138+
string: The table definition
139+
or
140+
dict(error=<error_message>): With error message of why it failed
141+
142+
"""
143+
@app.route('/api/get_table_definition', methods=['POST'])
144+
@protected_route
145+
def get_table_definition(jwt_payload):
146+
try:
147+
table_definition = DJConnector.get_table_definition(jwt_payload, request.json["schemaName"], request.json["tableName"])
148+
return table_definition
149+
except Exception as e:
150+
return str(e), 500
151+
130152
if __name__ == '__main__':
131153
app.run(host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)