TinyDB advanced use

Maybe it’s obvious, but I realize that you can store a list as value in a TinyDB. So I can use it to store records instead of a relational database as SQLite or similar.
Let’s do some examples.
I have to manage a list of products. I can store in TinyDB each product using product ID as key and a list of properties (for example, category, description, price) as value. When I need these properties I can recover product by ID and then read each value from the list. If I need a list of products, I can iterate each key and than read each value from list.
This is an easy way to emulate a database but there is a limitate way to querying it. We can expand it using another TinyDB storing a property as key and a list of associate IDs as value. For example I can have a record with a category as key and a list of IDs of products that belong to this category.
So if I need all the products of a category I can query the second TinyDB using category as key, read the value as a list of product ID and using that list query the first TinyDB using each item of the list as key.
I must update both TinyDB every time something change so if I remove a product, I must remove its ID from the list of the relative category and so on.

I know, using a real DB it’s the best practice but if you don’t want or if you cannot use other DB or extensions or if you want a really local database, you can use such solution.

4 Likes

the constraint with the tiny db component is the execution time of consumption for small lists of less than 1000 elements, but in lists of more than 6 thousand elements there are large waiting times

Right! I didn’t consider performance issues. It works for small projects due to the need of scan all the items every time.

3 posts were merged into an existing topic: TinyDB for storing global data in the app

I have created this advance level App, but anyone help me to take backup TinyDB and Restore. I am trying this Extension, but restore is not working due to image path.

Video Link: https://www.youtube.com/watch?v=bGNaEPJWQdo&t=3s
colin_tree_list_view_First_Frame%20-%20Copy