Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions dj_gui_api_server/DJConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def attempt_login(database_address, username, password):
List all schemas under the database

Parameters:
jwt_payload (dict): dictionary containing databaseAddress, username and password strings
jwt_payload (dict): Dictionary containing databaseAddress, username and password strings

Returns:
list<strings>: List of schemas names
Expand All @@ -47,7 +47,8 @@ def list_schemas(jwt_payload):
List all tables and their type give a schema

Parameters:
jwt_payload (dict): dictionary containing databaseAddress, username and password strings
jwt_payload (dict): Dictionary containing databaseAddress, username and password strings
schema_name (str): Name of schema to list all tables from

Returns:
dict(manual_tables=[<table_names>],
Expand Down Expand Up @@ -83,6 +84,24 @@ def list_tables(jwt_payload, schema_name):
print(table_name + ' is of unknown table type')

return tables_dict_list

"""
Get all tuples from table

Parameters:
jwt_payload (dict): Dictionary containing databaseAddress, username and password strings
schema_name (string): Schema name where to find the table under
table_name (string): Table name under the given schema, must be in camel case

Returns:
(tuples)
"""
@staticmethod
def fetch_tuples(jwt_payload, schema_name, table_name):
DJConnector.set_datajoint_config(jwt_payload)

schema_virtual_module = dj.create_virtual_module(schema_name, schema_name)
return getattr(schema_virtual_module, table_name).fetch(as_dict=True)

"""
Method to set credentials for database
Expand All @@ -104,10 +123,10 @@ def set_datajoint_config(jwt_payload):
Helper method for converting snake to camel case

Parameters:
string (string): string in snake format to convert to camel case
string (string): String in snake format to convert to camel case

Returns:
string: string formated in CamelCase notation
string: String formated in CamelCase notation
"""
@staticmethod
def snake_to_camel_case(string):
Expand Down
21 changes: 21 additions & 0 deletions dj_gui_api_server/DJGUIAPIServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,26 @@ def list_tables(jwt_payload):
except Exception as e:
return str(e), 500

"""
Route to fetch all tuples for a given table

Parameters:
header: (html:GET:Authorization): Must include in format of: bearer <JWT-Token>
body: (html:POST:JSON): {"schemaName": <schema_name>, "tableName": <table_name>} (NOTE: Table name must be in CamalCase)

Returns:
dict(tuples=[tuples_as_dicts])
or
dict(error=<error_message>): With error message of why it failed
"""
@app.route('/api/fetch_tuples', methods=['POST'])
@protected_route
def fetch_tuples(jwt_payload):
try:
table_tuples = DJConnector.fetch_tuples(jwt_payload, request.json["schemaName"], request.json["tableName"])
return dict(tuples = table_tuples)
except Exception as e:
return str(e), 500

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)