How To Use TinyDB

Published on February 6, 2022

A. Introduction

TinyDB is a storage component used to store data. Unlike variables, even if you exit the application, reboot the phone and open the application again, the data is still saved there. In this guide, you will learn how to use the TinyDB component to store data.

🏷️ Tags: #tutorials-and-guides

B. Blocks

The TinyDB component in App Inventor has 5 methods and 1 property block.

Before you get the data, you need to store the data first. The StoreValue block does this. The tag parameter specifies what tag the data will be for storing. A tag in data storage is a piece of text that helps you store and get data. The value is the data we will store.

After you stored the data, you have to get it. This is exactly what the GetValue block does. The system will attempt to find the data stored under the tag, and when the tag is not found, the socket valueIfTagNotThere is returned.

If you want to delete a piece of tag and data, you can use the ClearTag block.

The GetTags block gets a list of all tags in the database. From this block, we can also get a dictionary of all entries.

Kodular has a built-in block for this, but if you are working with App Inventor, use this.

The ClearAll block is used for clearing the entire database.

C. Sample app with TinyDB

D. Differences between TinyDB and other database components

  • TinyDB can only be accessed within your application. That means, only your application can edit, write and read the data of TinyDB.

  • TinyDB runs locally, and works well without internet access.

  • TinyDB runs well in your application usually. You can store up to a maximum of 100,000 entries, and the tag or value of each entry can be up to 8,388,607 characters. TinyWebDB, on the other hand, does not have offline support, and individual data values are limited to 500 characters, and users can store up to 2,000 characters.