TinyDB NameSpace Backup and Restore via CloudDB

This is yet another TinyDB backup and restore sample, this time using a CloudDB tag for each NameSpace, without using any Files or extensions.

It is meant to be embedded within the user's app, for personal apps not published widely.

I have tested it within the Companion to transfer my phone's Companion TinyDB contents to my desktop emulator Companion app.

Screen shots:
Startup
You get to choose which NameSpace you want to export/import, default=TinyDB1.
You must supply a unique CloudDB tag to catch your backup. In my case, I chose a familiar NYC Central Park sight.

For test purposes, I tried an export against my target emulator, to see what was there.
Startup2
It started out empty.

I then switched to my phone, and exported its Companion's TinyDB. The app reported 6 tags exported. to CloudB. (No image).

Switching back to my emulator and reconnecting to the Companion, I imported from that same CloudDB tag:
Startup4

Designer:

I added my own TinyDB instance, to avoid interfering with any of the app's TinyDB components.

This can all be copied to another Screen or Vertical Arrangement, to not mess up the rest of your app, using the Designer's Copy/Paste facilities.

Blocks Overview:

Block Details:

The Export Button

  • switches to the requested TinyDB NameSpace
  • Announces its intentions
  • Uses the new TinyDB .GetEntries block to get a dictionary holding all tags/values of the current NameSpace, and stores that into the requested CloudDB tag.

When the CoundDB storage operation completes, we announce it.

Just in case, we report CloudDB errors.


For an import, we

  • set up the TinyDB NameSpace to catch the import
  • Announce our intentions
  • ask for the data from CloudDB, hopefully using the same tag where it was exported, and returning an empty dictionary as default if nothing found. The empty dictionary will fail the restore gracefully, returning no keys/values.


This overcautious event catches the requested NameSpace backup tag/value dictionary, and loops through its dictionary restoring each key/value in it as a tag/value into TinyDB.

In retrospect, I should have renamed my CloudDB1 instance to CloudDBBackupRestore, to avoid interference with any user CloudDB instances.

I am doing that in my source.

TinyDB_CloudDB_export_import.aia (3.8 KB)

2 Likes

Hello. I'm trying to save values ​​from Tinydb to Cloudb to restore later. The list is:

Tag1 ["Value1","Value2","Value3","Value4"]
and:
Tag2 ["Value1","Value2","Value3","Value4"]

But when restoring, the values ​​are coming back repeated.
What's wrong?

First Tap

After:

How many times have you pressed the StoreTinyDB button ? This will add the values to the lists again.

I think twice actually. I've already paid attention by pressing Store Tinydb just once, but it still happens!

the same thing happens when I try to restore from Firebase, first tap for Tag and second tap for values, it's never automatic.

The problem is with how you create the lists you want to store:
image

These add item to lists blocks are cumulative, so if you don't clear the target list (FirstList) before doing this add, it gets longer and longer.

If your intention is for FirstList to hold Martin Lomas's 5 attributes, you should instead use the assignment

set global FirstList to MakeList(those 5 text blocks)

Use the blue mutator block to stretch out the Make a List block as needed.

Thank you very much for your help!

So I got one right?