-
Assume you have a db with multiple tables each with multiple documents.
You now open an instance of TinyDb with that db: with TinyDB("databasefile.db") as db:
db.all() #returns [] Because TinyDB passes the call to the TinyDB instance directly to the default Table (that might or might not be used) it returns an empty array. Under the moto:
Why don't we have to explicitly select the table we are working with? LMKWYT |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Simply put, it's for historical reasons 🙂 The very first design of TinyDB had only a single table. Relatively quickly I found that I needed to store multiple tables within the same database so I added the possibility to create new tables. But, crucially, in my mind (back in 2013) I thought that most use cases would probably only use a single table and having to explicitly create a table when one doesn't need multiple tables felt like an unnecessary burden to me. Now, almost 10 years later I agree that explicitly creating tables would indeed save a lot of confusion when people who used to use a single table start using multiple tables. But I really can't count how many projects need a single vs. multiple tables and at this point I fear that changing this would probably cause more confusion/code breakage than it would prevent. |
Beta Was this translation helpful? Give feedback.
Simply put, it's for historical reasons 🙂 The very first design of TinyDB had only a single table. Relatively quickly I found that I needed to store multiple tables within the same database so I added the possibility to create new tables. But, crucially, in my mind (back in 2013) I thought that most use cases would probably only use a single table and having to explicitly create a table when one doesn't need multiple tables felt like an unnecessary burden to me.
Now, almost 10 years later I agree that explicitly creating tables would indeed save a lot of confusion when people who used to use a single table start using…