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
19 changes: 19 additions & 0 deletions dj_gui_api_server/DJConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ def fetch_tuples(jwt_payload, schema_name, table_name):

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

"""
Method to get primary and secondary attributes of a 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:
dict(primary_keys=[<primary_key_names>], secondary_attributes=[<secondary_key_names])
"""
@staticmethod
def get_table_attributes(jwt_payload, schema_name, table_name):
DJConnector.set_datajoint_config(jwt_payload)

schema_virtual_module = dj.create_virtual_module(schema_name, schema_name)
return dict(primary_keys=getattr(schema_virtual_module, table_name).heading.primary_key, secondary_attributes=getattr(schema_virtual_module, table_name).heading.secondary_attributes)

"""
Get the table definition
Expand Down Expand Up @@ -156,6 +174,7 @@ def set_datajoint_config(jwt_payload):
dj.config['database.password'] = jwt_payload['password']

dj.conn(reset=True)


"""
Helper method for converting snake to camel case
Expand Down
9 changes: 9 additions & 0 deletions dj_gui_api_server/DJGUIAPIServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ def insert_tuple(jwt_payload):
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/get_table_attributes', methods=['POST'])
@protected_route
def get_table_attributes(jwt_payload):
try:
return DJConnector.get_table_attributes(jwt_payload, request.json["schemaName"], request.json["tableName"])
string: The table definition
or
string: With error message of why it failed, 500 error
Expand Down