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
- Download the EnhancedDB.aix file.
- Open MIT App Inventor.
- Click on Extensions > Import extension...
- Upload the
.aix
file and wait for the import to complete. - Drag and drop the EnhancedDB component onto your workspace.
Commands & Usage
1. Initialize the Database
Command: InitializeDB(dbName)
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)
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)
Description: Stores a key-value pair in the database.
Example:
SetValue("username", "JohnDoe");
SetValue("age", "25");
4. Retrieve a Value
Command: GetValue(tag, defaultValue)
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)
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()
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)
Description: Removes a specific key and its associated value from the database.
Example:
Remove("username");
8. Clear the Table
Command: ClearDB()
Description: Deletes all key-value pairs from the active table.
Example:
ClearDB();
9. Export Database as JSON
Command: ExportDB()
Description: Exports the entire database into a JSON string.
Example:
ExportDB(); // Returns "{\"username\":\"JohnDoe\",\"age\":\"25\"}"
10. Import Data from JSON
Command: ImportDB(jsonData)
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
- Initialize the database:
InitializeDB("UserDB");
- Set the active table:
SetTable("Users");
- Store user data:
SetValue("name", "Alice"); SetValue("email", "alice@example.com");
- Retrieve stored data:
GetValue("name", "Unknown"); // Returns "Alice"
- Check if email exists:
Exists("email"); // Returns true
- Export data:
ExportDB();
- 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.