@@ -98,19 +98,14 @@ def _list_tables(jwt_payload: dict, schema_name: str) -> dict:
9898 return tables_dict_list
9999
100100 @staticmethod
101- def _fetch_records (jwt_payload : dict , schema_name : str , table_name : str ,
101+ def _fetch_records (query ,
102102 restriction : list = [], limit : int = 1000 , page : int = 1 ,
103103 order = ['KEY ASC' ]) -> tuple :
104104 """
105- Get records from table .
105+ Get records from query .
106106
107- :param jwt_payload: Dictionary containing databaseAddress, username, and password
108- strings
109- :type jwt_payload: dict
110- :param schema_name: Name of schema
111- :type schema_name: str
112- :param table_name: Table name under the given schema; must be in camel case
113- :type table_name: str
107+ :param query: any datajoint object related to QueryExpression
108+ :type query: datajoint ``QueryExpression`` or related object
114109 :param restriction: Sequence of filters as ``dict`` with ``attributeName``,
115110 ``operation``, ``value`` keys defined, defaults to ``[]``
116111 :type restriction: list, optional
@@ -125,20 +120,17 @@ def _fetch_records(jwt_payload: dict, schema_name: str, table_name: str,
125120 can be paged
126121 :rtype: tuple
127122 """
128- _DJConnector ._set_datajoint_config (jwt_payload )
129-
130- schema_virtual_module = dj .create_virtual_module (schema_name , schema_name )
131123
132124 # Get table object from name
133- table = _DJConnector ._get_table_object (schema_virtual_module , table_name )
134- attributes = table .heading .attributes
125+ attributes = query .heading .attributes
135126 # Fetch tuples without blobs as dict to be used to create a
136127 # list of tuples for returning
137- query = table & dj .AndList ([
128+ query_restricted = query & dj .AndList ([
138129 _DJConnector ._filter_to_restriction (f , attributes [f ['attributeName' ]].type )
139130 for f in restriction ])
140- non_blobs_rows = query .fetch (* table .heading .non_blobs , as_dict = True , limit = limit ,
141- offset = (page - 1 )* limit , order_by = order )
131+ non_blobs_rows = query_restricted .fetch (* query .heading .non_blobs , as_dict = True ,
132+ limit = limit , offset = (page - 1 )* limit ,
133+ order_by = order )
142134
143135 # Buffer list to be return
144136 rows = []
@@ -181,45 +173,34 @@ def _fetch_records(jwt_payload: dict, schema_name: str, table_name: str,
181173
182174 # Add the row list to tuples
183175 rows .append (row )
184- return list (attributes .keys ()), rows , len (query )
176+ return list (attributes .keys ()), rows , len (query_restricted )
185177
186178 @staticmethod
187- def _get_table_attributes ( jwt_payload : dict , schema_name : str , table_name : str ) -> dict :
179+ def _get_attributes ( query ) -> dict :
188180 """
189- Method to get primary and secondary attributes of a table .
181+ Method to get primary and secondary attributes of a query .
190182
191- :param jwt_payload: Dictionary containing databaseAddress, username, and password
192- strings
193- :type jwt_payload: dict
194- :param schema_name: Name of schema to list all tables from
195- :type schema_name: str
196- :param table_name: Table name under the given schema; must be in camel case
197- :type table_name: str
183+ :param query: any datajoint object related to QueryExpression
184+ :type query: datajoint ``QueryExpression`` or related object
198185 :return: Dict with keys ``attribute_headers`` and ``attributes`` containing
199186 ``primary``, ``secondary`` which each contain a
200187 ``list`` of ``tuples`` specifying: ``attribute_name``, ``type``, ``nullable``,
201188 ``default``, ``autoincrement``.
202189 :rtype: dict
203190 """
204- _DJConnector ._set_datajoint_config (jwt_payload )
205- local_values = locals ()
206- local_values [schema_name ] = dj .VirtualModule (schema_name , schema_name )
207-
208- # Get table object from name
209- table = _DJConnector ._get_table_object (local_values [schema_name ], table_name )
210191
211- table_attributes = dict (primary = [], secondary = [])
212- for attribute_name , attribute_info in table .heading .attributes .items ():
192+ query_attributes = dict (primary = [], secondary = [])
193+ for attribute_name , attribute_info in query .heading .attributes .items ():
213194 if attribute_info .in_key :
214- table_attributes ['primary' ].append ((
195+ query_attributes ['primary' ].append ((
215196 attribute_name ,
216197 attribute_info .type ,
217198 attribute_info .nullable ,
218199 attribute_info .default ,
219200 attribute_info .autoincrement
220201 ))
221202 else :
222- table_attributes ['secondary' ].append ((
203+ query_attributes ['secondary' ].append ((
223204 attribute_name ,
224205 attribute_info .type ,
225206 attribute_info .nullable ,
@@ -229,7 +210,7 @@ def _get_table_attributes(jwt_payload: dict, schema_name: str, table_name: str)
229210
230211 return dict (attribute_headers = ['name' , 'type' , 'nullable' ,
231212 'default' , 'autoincrement' ],
232- attributes = table_attributes )
213+ attributes = query_attributes )
233214
234215 @staticmethod
235216 def _get_table_definition (jwt_payload : dict , schema_name : str , table_name : str ) -> str :
@@ -270,7 +251,7 @@ def _insert_tuple(jwt_payload: dict, schema_name: str, table_name: str,
270251 """
271252 _DJConnector ._set_datajoint_config (jwt_payload )
272253
273- schema_virtual_module = dj .create_virtual_module (schema_name , schema_name )
254+ schema_virtual_module = dj .VirtualModule (schema_name , schema_name )
274255 getattr (schema_virtual_module , table_name ).insert (tuple_to_insert )
275256
276257 @staticmethod
@@ -326,7 +307,7 @@ def _update_tuple(jwt_payload: dict, schema_name: str, table_name: str,
326307 """
327308 conn = _DJConnector ._set_datajoint_config (jwt_payload )
328309
329- schema_virtual_module = dj .create_virtual_module (schema_name , schema_name )
310+ schema_virtual_module = dj .VirtualModule (schema_name , schema_name )
330311 with conn .transaction :
331312 [getattr (schema_virtual_module , table_name ).update1 (t ) for t in tuple_to_update ]
332313
@@ -351,7 +332,7 @@ def _delete_records(jwt_payload: dict, schema_name: str, table_name: str,
351332 """
352333 _DJConnector ._set_datajoint_config (jwt_payload )
353334
354- schema_virtual_module = dj .create_virtual_module (schema_name , schema_name )
335+ schema_virtual_module = dj .VirtualModule (schema_name , schema_name )
355336
356337 # Get table object from name
357338 table = _DJConnector ._get_table_object (schema_virtual_module , table_name )
0 commit comments