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