mrtinydbutils.tables – Tables for TinyDB

It implements additional tables for TinyDB.

Module author: Michael Rippstein <michael@anatas.ch>

TableUuid

class mrtinydbutils.tables.TableUuid(storage: tinydb.storages.Storage, name: str, cache_size: int = 10)[source]

Bases: tinydb.table.Table

Table with uuid ids.

Beschreibung

_get_next_id()str[source]

Return the ID for a newly inserted document.

Returns

Return type

str

TableTimestamp

class mrtinydbutils.tables.TableTimestamp(storage: tinydb.storages.Storage, name: str, cache_size: int = 10)[source]

Bases: tinydb.table.Table

Table with timestamps in every entry.

insert(document: MutableMapping)int[source]

Insert a new document into the table.

Parameters

document – the document to insert

Returns

the inserted document’s ID

Return type

int

insert_multiple(documents: Iterable[MutableMapping])List[int][source]

Insert multiple documents into the table.

Parameters

documents – a Iterable of documents to insert

Returns

a list containing the inserted documents’ IDs

Return type

List[int]

update(fields: Union[Mapping, Callable[[Mapping], None]], cond: Optional[tinydb.queries.Query] = None, doc_ids: Optional[Iterable[int]] = None)List[int][source]

Update all matching documents to have a given set of fields.

Parameters
  • fields – the fields that the matching documents will have or a method that will update the documents

  • cond – which documents to update

  • doc_ids – a list of document IDs

Returns

a list containing the updated document’s ID

Return type

List[int]

update_multiple(updates: Iterable[Tuple[Union[Mapping, Callable[[Mapping], None]], tinydb.queries.Query]])List[int][source]

Update all matching documents to have a given set of fields.

Parameters
  • updates – TODO

  • todo: (.) – Parameter description:

Returns

a list containing the updated document’s ID

Return type

List[int]

created_key: str = '_created'

.

updated_key: str = '_updated'

.

TableUuidTimestamp

class mrtinydbutils.tables.TableUuidTimestamp(storage: tinydb.storages.Storage, name: str, cache_size: int = 10)[source]

Bases: mrtinydbutils.tables.TableUuid, mrtinydbutils.tables.TableTimestamp

A table class with timestamps and UUID as doc_id.