All About TinyDB
(At least I hope it's all)
For help see the reference
What is a TinyDB?
The TinyDB component is a database component. There are other database components like Firebase, FusionTables and TinyWebDB, but these
are online databases. This is also the major difference between the TinyDB and all other databases. This component allow you to create
a database that is only accessible from your app (at least for non-rooted phones). If you don't know what a database is, you better
check
Wikipedia for that, because databases are very useful for
developers. Luckily,
Merriam-Webster has prepared the
following definition for you:
DATABASE: [...] a usually large collection of data organized especially for rapid search and retrieval
Databases store values in "tags" and you can use these to get the stored values.
As of January 2019, you can create different datastores in a single app.
You need to change the namespace property of the TinyDB component for that.
It acts like a name for the table in your database.
What can a TinyDB used for?
Generally speaking, everything what a database can be used for, although I wouldn't recommend them for large databases. Typically you
use them for storing whether the user is registrated or not, the user's username, a high-score. Because of the root access it is not
recommended to store whether the user is using the free version of an app or not. You can use them to share data between screens, but
not between apps. An important difference between the TinyDB and the variables is that the storage is persistent. That means that the
values are still there, in contrast to variables, which are initialized with whatever value you choose each time you start the app.
What can you do with a TinyDB?
You can store every kind of data, e.g. strings, numbers, booleans and even lists. As mentioned before, you could store complex lists
with sublists, but I don't recommend that because it gets too messy. You can do normal list operations such as select list item, but
also more complicated ones such as lookup in pairs. But remove list item, replace list item, etc. do
not work, because they
don't store the data in the TinyDB, but in a copy of it. The data is stored as a string, which will work for all
data types except the component type.
Be careful: The companion has only one database, so all apps in live development share the same database.