class documentation

class TinyDBBetterTable(Table):

View In Hierarchy

This class is an add-on to TinyDB's Table class. It removes some computations that are not necessary in ACME.

  • Document ID's are always strings.
  • Since document ID's are strings, the conversion during each update is not necessary anymore.
Class Method assign Class method to assign this class to an existing Table instance.
Method _get_next_id Return the ID for a newly inserted document. This method overloads the original method to return the ID as a string.
Method _update_table Perform a table update operation.
@classmethod
def assign(self, table: Table):

Class method to assign this class to an existing Table instance.

Parameters
selfUndocumented
table:TableA TinyDB Table instance.
def _get_next_id(self) -> str:

Return the ID for a newly inserted document. This method overloads the original method to return the ID as a string.

Returns
strThe ID for the new document.
def _update_table(self, updater: Callable[[dict[int, Mapping]], None]):

Perform a table update operation.

The storage interface used by TinyDB only allows to read/write the complete database data, but not modifying only portions of it. Thus, to only update portions of the table data, we first perform a read operation, perform the update on the table data and then write the updated data back to the storage.

As a further optimization, we don't convert the documents into the document class, as the table data will not be returned to the user.