TinyDB

Last Updated On 2021-07-16

Version 2MinSDK 7Tutorial Video

TinyDB is a non-visible component that stores data for an app.

Apps created with App Inventor are initialized each time they run: If an app sets the value of a variable and the user then quits the app, the value of that variable will not be remembered the next time the app is run. In contrast, TinyDB is a persistent data store for the app, that is, the data stored there will be available each time the app is run. An example might be a game that saves the high score and retrieves it each time the game is played.

Data items are strings stored under tags . To store a data item, you specify the tag it should be stored under. Subsequently, you can retrieve the data that was stored under a given tag.

There is only one data store per app. Even if you have multiple TinyDB components, they will use the same data store. To get the effect of separate stores, use different keys. Also each app has its own data store. You cannot use TinyDB to pass data between two different apps on the phone, although you can use TinyDb to shares data between the different screens of a multi-screen app.

When you are developing apps using the AI Companion, all the apps using that companion will share the same TinyDb. That sharing will disappear once the apps are packaged. But, during development, you should be careful to clear the TinyDb each time you start working on a new app.


Properties

You can set the below properties in the UI part of the builder.

  • Namespace - it's a string value which is set to tinydb1 by default.

Block Properties

You can set the below blocks properties in the blocks section of the builder.

Namespace

Namespace for storing data.



Methods

You can set the below method blocks in the blocks section of the builder.

ClearAll

Clear the entire data store.

ClearTag

Clear the entry with the given tag.

GetTags

Return a list of all the tags in the data store.

GetValue

Retrieve the value stored under the given tag. If there's no such tag, then return valueIfTagNotThere.

StoreValue

Store the given value under the given tag. The storage persists on the phone when the app is restarted.