You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that update_multiple() doesn't support updating data by the corresponding doc_id using QueryLike. So this is my simple implementation for it:
classMyTable(Table):
def__init__(self, storage: Storage, name: str):
super().__init__(storage, name)
defupdate_multiple_by_id(
self,
updates: Iterable[
Tuple[Union[Mapping, Callable[[Mapping], None]], int]
],
) ->List[int]:
""" Update all matching documents to have a given set of fields. :returns: a list containing the updated document's ID """# Define the function that will perform the updatedefperform_update(fields, table, doc_id):
ifcallable(fields):
# Update documents by calling the update function provided# by the userfields(table[doc_id])
else:
# Update documents by setting all fields from the provided# datatable[doc_id].update(fields)
# Perform the update operation for documents specified by a query# Collect affected doc_idsupdated_ids= []
defupdater(table: dict):
# We need to convert the keys iterator to a list because# we may remove entries from the ``table`` dict during# iteration and doing this without the list conversion would# result in an exception (RuntimeError: dictionary changed size# during iteration)forfields, doc_idinupdates:
ifdoc_idintable:
# Add ID to list of updated documentsupdated_ids.append(doc_id)
# Perform the update (see above)perform_update(fields, table, doc_id)
# Perform the update operation (see _update_table for details)self._update_table(updater)
returnupdated_ids
Then replace the TinyDB.table_class by the MyTable before creating a TinyDB instance.
TinyDB.table_class=MyTable
The text was updated successfully, but these errors were encountered:
It seems that update_multiple() doesn't support updating data by the corresponding doc_id using QueryLike. So this is my simple implementation for it:
Then replace the TinyDB.table_class by the MyTable before creating a TinyDB instance.
The text was updated successfully, but these errors were encountered: