mrtinydbutils.middlewares – Middlewares for TinyDB

TinyDB Middelware Classes.

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

DocIdToEntryMiddleware

class mrtinydbutils.middlewares.DocIdToEntryMiddleware(storage_cls)[source]

Bases: tinydb.middlewares.Middleware

Add the doc_id to every entry.

It adds the doc_id to every entry at the reading and removing it at the writing of the the table. The doc_id is stored with the key definded in the class attribute doc_id_key.

Warning

If the key exists in the document it will overwriten!

read()Optional[dict][source]

Add the doc_id to every document.

write(data: dict)None[source]

Remove the doc_id from every document.

doc_id_key: str = '_id'

The name of the key.