Issue with tinyDB and namespaces

I am using tinyDB to pass data between screens and to persistently save them.
For some reason in my quite complex app the tinyDB data in my Screen 2 did not appear in Screen1, also the data were still available when re-entering screen2.
After some trial and error I observed that explicitely setting a namespace solves the problem:

To double check, I created another app with 2 screens, also sharing data via tinyDB. Surprisingly there it was not necessary to set the namespace.

Besides it would be great if this namespace-block would be described more detailed in the docs.

Thanks!

I can assure you that TinyDB is working properly, which you confirmed in the second test application. You are just doing something wrong to tell you what, you would have to share your aia file.

yes, you will have to use the same namespace in Screen1 and Screen2 to be able to get data from the same TinyDB

Namespace
Namespace for storing data.

you are correct, the documentation is not very detailed...
do you have any suggestion, how this could be explained better? I'm sure, the MIT App Inventor team is open to improvements...

Taifun


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

Hi Taifun,

thanks for the quick reply. :slight_smile:

As mentioned, rare thing is that when I created this test app to double-check the behavior for both screens by default the same namespace seemed to be assigned.

What could be improved for the tinyDB docu is to mention the term "namespace" at all in the description.
What is a namespace, what is it good for and perhaps what causes creation of a new namespace, e.g. in my case adding a new screen. Perhaps a hint, in doubt to specify a namespace in order to have clear relations.

thank you, I will assign this thread to @ewpatton to clarify this in the documentation
Taifun

The namespace defaults to the component name TinyDB. If you have TinyDB1 on one screen and TinyDB2 on the other, it won't work. In this case, change the component name or set the namespace.

Good to know that, thanks! :slight_smile:

Name space for both screens is TinyDB1:
image
image

I began working on this app quite long ago, the second screen was added lately. So, is it possible that my observation with having a different namespace is caused by this fact, i.e. some issue due to several AI2 updates happening over time?

Check that you haven't accidentally changed the space names here.

tinyDb

Already done, it's the same.

Just now I exported the .aia and unzipped the src (interesting thing, did it for the 1st time :slight_smile: ).

In Screen1.scm I founnd this:
{"$Name":"TinyDB1","$Type":"TinyDB","$Version":"2","Namespace":"TDB_global","Uuid":"1925947564"}

In Screen2.scm this:
{"$Name":"TinyDB1","$Type":"TinyDB","$Version":"2","Uuid":"447471686"}

So, it seems that only in Screen 1 a namespace is explicitely defined.

This means that on Screen2 you have defined a namespace, while on Screen1 it has remained the default.
If you need more help put the aia file with the problem here. Then we will find the source of the problem.

Dear Patryk_F,

might be that I "accidently" caused a change in Screen2's TinyDB namespace. It's the first time I'm using TinyDB, perhaps I unintentionally modified things while playing around with TinyDB.

You helped me a lot to get a clearer picture here, so for this topic I currently do not need further support.

In general I want to thank you and also Taifun for that great support! :+1:

So, to make it more clear:

It doesn't matter if I have 3 TinyDB instances spread across the screens, they will all act as one TinyDB instance unless I change the Namespaces.

To the Which; By changing the Namespaces of each of them, they will act as different TinyDB instances, regardless of whether they have the same name (TinyDB).

Example: {TinyDB_name : Namespace_name}

  • Tdb : usr =/= Tdb : preferences, and =/= Tdb : configuration

  • And each one with its Tags (of course)

That way I avoid using the TinyDBX extension, because each one of tghem has its own UUID

Yes

Set the namespace then call the tags for that namespace.

It is recommended to always set the namespace.

1 Like