📊

Building an Expense Tracker with ESA Database

Oct 11, 2024

Advanced ESA Database Tutorial Notes

Overview

  • Tutorial covers from basics to advanced concepts of ESA database.
  • Building a simple expense tracker app to monitor, manage, and analyze expenses.

ESA Database Basics

  • Definition: Cross-platform, NoSQL, local database for Flutter.
  • Platforms Supported: Android, iOS, desktop, and web.
  • Storage Engines:
    • ESA Core: Ultra-fast engine for mobile apps.
    • Escalate Engine: Wrapper around Escalate for integration.

Key Features of ESA Database

  • NoSQL Format: Stores data in JSON documents instead of tabular format.
  • Local Storage: Database is stored on the user's device.
  • Scalability: Can store hundreds of thousands of records.
  • Asynchronous Queries: Avoids blocking other calls.
  • Open Source: Freely available source code.
  • ACID Compliance: Ensures atomicity, consistency, isolation, and durability of transactions.
  • Full-Text Search: Comprehensive search functionality.
  • Static Typing: Early error detection and reduced debugging time.

Reasons to Use a Local Database

  • Offline Access: Users can interact without internet.
  • Faster Access: Quick local data retrieval.
  • Data Persistence: User preferences and settings are stored locally.
  • Data Caching: Reduces repeated downloads from the server.
  • Reduced Data Exposure: Enhances security by limiting data transmission.

Creating the Project

  1. Initialize a Flutter application:
    • Command: flutter create expense_tracker
  2. Add Dependencies:
    • ESA Database
    • ESA Flutter Libs
    • Path Provider
    • ESA Generator and Build Runner for code generation.

Setting Up the Database

  • Define the database and initialize parameters.
  • Create collections in the database schema:
    • Budget: Holds unique ID, month, year, and amount.
    • Income: Displays list of income sources.
    • Expense: Contains ID, amount, date, enums for category, and payment methods.
    • Receipt: Holds ID and name of uploaded receipt files.

Indexing and Relationships

  • Indexing: Optimizes search functionality.
  • Relationships:
    • EZLinks: One-to-many relationship between Expense and Receipt.
    • Backlinks: Reverse relationships to associate receipts with specific expenses.

Interacting with the Database

Repository Design

  • Create an abstract class for repository methods:
    • CRUD operations (Create, Read, Update, Delete)
    • Specific queries for expenses, budgets, and receipts.

Querying the Database

  • Use filter clauses for specific searches (e.g., by date, category, amount range).
  • Examples of specific functions for querying:
    • Get expenses by today.
    • Get total expenses by category.
    • Full-text search in expense descriptions.

User Interface Development

  • Implementing user interaction through Dart logic and UI components.
  • Implement state management using Riverpod for handling app state and data.

Setting Up Riverpod

  • Install necessary dependencies for Riverpod.
  • Create notifier classes for managing budget and expense states.
  • Use methods to manage and update state based on user actions in the UI.

Conclusion

  • The tutorial covers setting up a complete expense tracking application using ESA database with Flutter.
  • Emphasizes understanding database operations, data persistence, and user interface integration.