@@ -69,23 +69,19 @@ def wrapper(self, *args, **kwargs):
6969 return wrapper
7070
7171
72- def _batchify (value ):
72+ def _wrap_any_rows (value ):
7373 def _is_row_but_not_batch_row (thing ):
7474 return isinstance (thing , anvil .tables .Row ) and not isinstance (thing , BatchRow )
75-
76- def _batchify_rows (rows ):
77- batch_table = BatchTable .of_row (rows [0 ])
78- return [batch_table .get_batch_row (row ) for row in rows ]
79-
75+
8076 if _is_row_but_not_batch_row (value ):
81- return _batchify_rows ([ value ])[ 0 ]
77+ return BatchRow ( value )
8278 elif isinstance (value , list ) and value and _is_row_but_not_batch_row (value [0 ]):
83- return _batchify_rows ( value )
79+ return [ BatchRow ( row ) for row in value ]
8480 else :
8581 return value
8682
8783
88- def debatchify (value ):
84+ def _unwrap_any_rows (value ):
8985 if isinstance (value , BatchRow ):
9086 return value .row
9187 elif isinstance (value , list ) and value and isinstance (value [0 ], BatchRow ):
@@ -94,24 +90,24 @@ def debatchify(value):
9490 return value
9591
9692
97- def _debatchify_dict_values (_dict ):
98- return {key : debatchify (value ) for key , value in _dict .items ()}
93+ def _unwrap_any_row_values (_dict ):
94+ return {key : _unwrap_any_rows (value ) for key , value in _dict .items ()}
9995
10096
101- def debatchify_inputs (func ):
97+ def unwrap_any_input_rows (func ):
10298 @wraps (func )
10399 def out_function (* args , ** kwargs ):
104100 return func (
105- * [debatchify (arg ) for arg in args ],
106- ** _debatchify_dict_values (kwargs ),
101+ * [_unwrap_any_rows (arg ) for arg in args ],
102+ ** _unwrap_any_row_values (kwargs ),
107103 )
108104 return out_function
109105
110106
111107@portable_class
112108class BatchRow (anvil .tables .Row ):
113109 def __init__ (self , row ):
114- self ._cache = {} # debatchified
110+ self ._cache = {} # unwrapped_rows
115111 self ._deleted = False
116112 self ._row = None
117113 self .row = row
@@ -153,11 +149,11 @@ def __hash__(self):
153149 @if_not_deleted
154150 def __getitem__ (self , column ):
155151 if column in self ._cache :
156- return _batchify (self ._cache [column ])
152+ return _wrap_any_rows (self ._cache [column ])
157153 value = self .row [column ]
158154 if _batching :
159155 self ._cache [column ] = value
160- return _batchify (value )
156+ return _wrap_any_rows (value )
161157
162158 @if_not_deleted
163159 def __setitem__ (self , column , value ):
@@ -166,15 +162,14 @@ def __setitem__(self, column, value):
166162 @if_not_deleted
167163 def update (self , ** column_values ):
168164 global _update_queue
169- debatchified_column_values = _debatchify_dict_values (column_values )
165+ unwrapped_column_values = _unwrap_any_row_values (column_values )
170166 if not _batching :
171- return self .row .update (** debatchified_column_values )
172- self ._cache .update (debatchified_column_values )
167+ return self .row .update (** unwrapped_column_values )
168+ self ._cache .update (unwrapped_column_values )
173169 if self ._row is None :
174170 return # cache update implicitly updates batch_add, with no need for batch_update then
175- _update_queue [self ].update (debatchified_column_values )
171+ _update_queue [self ].update (unwrapped_column_values )
176172
177-
178173 @if_not_deleted
179174 def delete (self ):
180175 global _add_queue , _delete_queue
@@ -247,15 +242,15 @@ def search(self, *args, **kwargs):
247242 process_batch ()
248243 return BatchSearchIterator (
249244 self ,
250- debatchify_inputs (self .table .search )(* args , ** kwargs )
245+ unwrap_any_input_rows (self .table .search )(* args , ** kwargs )
251246 )
252247
253248 def get (self , * args , ** kwargs ):
254249 if _add_queue or _update_queue or _delete_queue :
255250 print ("AutoBatch: process_batch triggered early by get" )
256251 process_batch ()
257252 return self .get_batch_row (
258- debatchify_inputs (self .table .get )(* args , ** kwargs )
253+ unwrap_any_input_rows (self .table .get )(* args , ** kwargs )
259254 )
260255
261256 def get_by_id (self , row_id , * args , ** kwargs ):
@@ -268,10 +263,10 @@ def get_by_id(self, row_id, *args, **kwargs):
268263
269264 def add_row (self , ** column_values ):
270265 global _add_queue
271- debatchified_column_values = _debatchify_dict_values (column_values )
266+ unwrapped_column_values = _unwrap_any_row_values (column_values )
272267 if not _batching :
273- return _batchify (self .table .add_row (** debatchified_column_values ))
274- batch_row = BatchRow .from_batched_add (debatchified_column_values , batch_table = self )
268+ return _wrap_any_rows (self .table .add_row (** unwrapped_column_values ))
269+ batch_row = BatchRow .from_batched_add (unwrapped_column_values , batch_table = self )
275270 _add_queue [self ].append (batch_row )
276271 return batch_row
277272
0 commit comments