[F/OS] EnhancedDB: A Powerful TinyDB Alternative Using SQLite for MIT App Inventor

EnhancedDB Extension - User Guide

Introduction

EnhancedDB is an advanced local database extension for MIT App Inventor. It is built on SQLite, allowing for efficient data storage, retrieval, and manipulation. Unlike TinyDB, EnhancedDB supports multiple tables, JSON import/export, and key existence verification, making it a powerful tool for app developers.

Features

  • Persistent SQLite storage
  • Support for multiple tables
  • Efficient insertion, retrieval, and deletion
  • Export and import data in JSON format
  • Retrieve all stored keys
  • Check if a key exists

Installation

  1. Download the EnhancedDB.aix file.
  2. Open MIT App Inventor.
  3. Click on Extensions > Import extension...
  4. Upload the .aix file and wait for the import to complete.
  5. Drag and drop the EnhancedDB component onto your workspace.

Commands & Usage

1. Initialize the Database

Command: InitializeDB(dbName)
InitializeDB_Method

Description: Initializes the database with the given name. This must be called before any other function.

Example:

InitializeDB("MyDatabase");

2. Set Active Table

Command: SetTable(tableName)
SetTable_Method

Description: Defines the table in which data will be stored. If the table does not exist, it is created automatically.

Example:

SetTable("Users");

3. Store a Key-Value Pair

Command: SetValue(tag, value)
SetValue_Method

Description: Stores a key-value pair in the database.

Example:

SetValue("username", "JohnDoe");
SetValue("age", "25");

4. Retrieve a Value

Command: GetValue(tag, defaultValue)
GetValue_Method

Description: Retrieves the value associated with a key. If the key does not exist, it returns the default value.

Example:

GetValue("username", "Guest");

5. Check If a Key Exists

Command: Exists(tag)
Exists_Method

Description: Checks if a key exists in the database.

Example:

Exists("username"); // Returns true if "username" exists, otherwise false

6. Retrieve All Stored Keys

Command: GetAllKeys()
GetAllKeys_Method

Description: Returns a list of all keys stored in the current table.

Example:

GetAllKeys(); // Returns ["username", "age"]

7. Delete a Key-Value Pair

Command: Remove(tag)
Remove_Method

Description: Removes a specific key and its associated value from the database.

Example:

Remove("username");

8. Clear the Table

Command: ClearDB()
ClearDB_Method
Description: Deletes all key-value pairs from the active table.

Example:

ClearDB();

9. Export Database as JSON

Command: ExportDB()
ExportDB_Method

Description: Exports the entire database into a JSON string.

Example:

ExportDB(); // Returns "{\"username\":\"JohnDoe\",\"age\":\"25\"}"

10. Import Data from JSON

Command: ImportDB(jsonData)
ImportDB_Method

Description: Imports data into the database from a JSON string.

Example:

ImportDB("{\"city\":\"New York\",\"country\":\"USA\"}");

Example App Flow

Scenario: Creating a User Database

  1. Initialize the database:
    InitializeDB("UserDB");
    
  2. Set the active table:
    SetTable("Users");
    
  3. Store user data:
    SetValue("name", "Alice");
    SetValue("email", "alice@example.com");
    
  4. Retrieve stored data:
    GetValue("name", "Unknown"); // Returns "Alice"
    
  5. Check if email exists:
    Exists("email"); // Returns true
    
  6. Export data:
    ExportDB();
    
  7. Delete a key:
    Remove("email");
    

Files and Media

AIX (Build with Fast Cli): com.bosonshiggs.enhanceddb.aix (60.6 KB)
AIA: EnhancedDB.aia (64.5 KB)
GitHub: GitHub - iagolirapasssos/EnhancedDB: EnhancedDB: Advanced SQLite Extension for MIT App Inventor
Future videos: https://www.youtube.com/@prof.iagolira

Conclusion

EnhancedDB is a powerful SQLite-based extension that significantly improves data management capabilities in MIT App Inventor. It provides a robust and scalable way to handle persistent data efficiently.

Start integrating EnhancedDB in your projects today and take advantage of its advanced storage capabilities!

For further support, visit the MIT App Inventor Community.

4 Likes

On first review, this appears to look and operate in exactly the same way as tinyDB ?

What is different ?

Exactly :slight_smile:

1 Like

The idea is not to be too far removed from Tiny, because I really like it. I decided to add just a few improvements like importing JSON and creating tables. Later, and perhaps with the help of other devs, we will ship more improvements.

online?

Sorry, it was a typo.