Skip to content

Commit 0964024

Browse files
authored
Merge pull request #17 from Synicix/get_attributes
Added get table attribute route
2 parents 2f368ca + f168c71 commit 0964024

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

dj_gui_api_server/DJConnector.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ def fetch_tuples(jwt_payload, schema_name, table_name):
102102

103103
schema_virtual_module = dj.create_virtual_module(schema_name, schema_name)
104104
return getattr(schema_virtual_module, table_name).fetch(as_dict=True)
105+
106+
"""
107+
Method to get primary and secondary attributes of a table
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+
dict(primary_keys=[<primary_key_names>], secondary_attributes=[<secondary_key_names])
116+
"""
117+
@staticmethod
118+
def get_table_attributes(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 dict(primary_keys=getattr(schema_virtual_module, table_name).heading.primary_key, secondary_attributes=getattr(schema_virtual_module, table_name).heading.secondary_attributes)
105123

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

158176
dj.conn(reset=True)
177+
159178

160179
"""
161180
Helper method for converting snake to camel case

dj_gui_api_server/DJGUIAPIServer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ def insert_tuple(jwt_payload):
158158
body: (html:POST:JSON): {"schemaName": <schema_name>, "tableName": <table_name>} (NOTE: Table name must be in CamalCase)
159159
160160
Returns:
161+
dict(tuples=[tuples_as_dicts])
162+
or
163+
dict(error=<error_message>): With error message of why it failed
164+
"""
165+
@app.route('/api/get_table_attributes', methods=['POST'])
166+
@protected_route
167+
def get_table_attributes(jwt_payload):
168+
try:
169+
return DJConnector.get_table_attributes(jwt_payload, request.json["schemaName"], request.json["tableName"])
161170
string: The table definition
162171
or
163172
string: With error message of why it failed, 500 error

0 commit comments

Comments
 (0)