What is the tinydb namespace property?

1,424 views
Skip to first unread message

bianca fenice

unread,
Oct 2, 2018, 5:54:16 AM10/2/18
to MIT App Inventor Forum
As in the subject: I want to know what is the tinydb namespace property and what it does and how can I use it

Thanks in advance.

Chris Ward

unread,
Oct 2, 2018, 7:17:53 AM10/2/18
to MIT App Inventor Forum
Hello Bianca

There are two ways that it can be used. Firstly, you can have one TinyDB, containing more than one namespace, to logically arrange stored values. For example if I stored a list of engineering materials in TinyDB, I might have namespaces for Metals, Plastics, Wood. I have tested this, store and restore, works well.

Another use is to give different Screens their own TinyDB. I have not tested this scenario. On Screen1 you might have TinyDB_Materials. On Screen2 you might have TinyDB_Fluids. With each TinyDB having different namespaces, they would be exclusive to their screen whereas before there was only one TinyDB shared with all Screens.

bianca fenice

unread,
Oct 2, 2018, 9:02:29 AM10/2/18
to MIT App Inventor Forum
Thanks for the quick answer.

I think I got it: it's kinda of having more tDBs in the same app or kinda of having more "tables" in the same tDB into the same app or different arrays (or dictionary object) in the same function... well... kind of...

So under different Namespaces into the same DB we can use the same tag to store and retrive different values? Am I right?

But instead calling it "Namespace" isn't better to call it just Table? This way is more clear and intuitive IMO.

Anyway thanks for the clarification.



Susanta K Beura

unread,
Oct 2, 2018, 9:09:23 AM10/2/18
to MIT App Inventor Forum
Hi @Chris_Ward,

I have used different TinyDB on different screens. But never tried multiple namespaces with a single instance of TinyDB. Please provide more details on how you are using multiple namespaces with a single TinyDB and how they use to be accessed from multiple screens.

Thank you.

Regards,
Susanta

Taifun

unread,
Oct 2, 2018, 11:06:17 AM10/2/18
to mitappinv...@googlegroups.com
I have used different TinyDB on different screens
there is only one TinyDB, see the documentation http://ai2.appinventor.mit.edu/reference/components/storage.html#TinyDB

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

Apps created with App Inventor are initialized each time they run. This means that 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. The data stored in a TinyDB 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.

Each app has its own data store. 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. You cannot use the TinyDB to pass data between two different apps on the phone, although you can use the TinyDB to share 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 and installed on the phone. During development you should be careful to clear the Companion app's data each time you start working on a new app.


alternatively use TinyDBX Extension by Juan Antonio to use several TinyDBs in an app


Taifun


Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Chris Ward

unread,
Oct 2, 2018, 12:13:37 PM10/2/18
to MIT App Inventor Forum
Hello Susanta

I have posted an example using a Multi-Namespace TinyDB:

Juan Antonio

unread,
Oct 2, 2018, 1:05:37 PM10/2/18
to MIT App Inventor Forum
Reply all
Reply to author
Forward
0 new messages