How to Extend TinyDB

Storages

To write a custom storage, subclass Storage:

To use your custom storage, use:

db = TinyDB(storage=YourStorageClass)

提示

TinyDB will pass all arguments and keyword arguments (except for storage) to your storage's __init__.

For example implementations, check out the source of JSONStorage or MemoryStorage.

Middlewares

To write a custom storage, subclass Middleware:

To use your middleware, use:

db = TinyDB(storage=YourMiddleware(SomeStorageClass))

For example implementations, check out the source of CachingMiddleware or ConcurrencyMiddleware.