NewPlatano

Building a Budget Buddy App with React Native Expo SQLite

Beto, February 18, 2024 · 43,154 views

Learn how to create a budget application using React Native with Expo SDK 50 and the Expo SQLite library. The app stores all data locally on the device, making it fully functional offline and private. It’s a practical example for anyone wanting to build personal finance apps or any app that benefits from local SQL storage.

You’ll see how to set up the SQLite database, create tables, insert and query data, and build a simple UI to add, display, and delete expenses. The app also demonstrates scaling with categories and types, plus UI improvements like auto-sizing text for large numbers.

What's inside

  • Introduction to the budget app concept and Expo SQLite
  • Benefits of local SQLite storage for offline and private data
  • Database schema: tables for categories and transactions
  • Creating and populating the SQLite database with SQL commands
  • Using Expo SQLite API to query and manipulate data in React Native
  • Handling UI with React Navigation and auto-sizing text for large numbers
  • Managing data updates: adding, deleting, and recalculating totals
  • Exporting and scaling options for the database and app

Introduction to the budget app concept and Expo SQLite

I open by introducing a budget app built with Expo SDK 50 and the Expo SQLite library. This library is bundled with Expo and provides a fully featured SQL database on the device. The app tracks expenses and incomes locally without requiring internet access, which is ideal for privacy and offline use.

The app’s UI looks simple, similar to a todo list, but it supports complex features like querying expense types and categories from the database. This foundation allows scaling to more advanced financial apps with relational data.

Benefits of local SQLite storage for offline and private data

Storing data locally with SQLite means the app does not depend on an internet connection. This is perfect for budget apps where users want to keep their financial data private and accessible anytime.

SQLite is built into all phones and many computers, making it a reliable choice. I highlight that over 1 trillion SQLite databases are active worldwide, showing its ubiquity and stability.

Database schema: tables for categories and transactions

The app uses a simple but relational database schema with two main tables: categories and transactions. Categories hold types like “dining out” or “bonus,” while transactions store individual expense or income records linked to categories by foreign keys.

This relational setup enables querying expenses by category, summing totals, and building insights. I show the SQL commands to create these tables and insert initial data.

Creating and populating the SQLite database with SQL commands

Before building the React Native app, I demonstrate creating the SQLite database using the sqlite3 CLI tool. You create a database file, then run SQL commands to create tables and insert sample data.

This approach allows you to prepare a database file that can be imported into the app later, or you can create and modify the database entirely from within the app using Expo SQLite.

Using Expo SQLite API to query and manipulate data in React Native

Inside the React Native app, the Expo SQLite API is used to open the database, run queries, and update data. I show how to fetch categories and transactions, insert new expense records, and delete entries by long press.

The app recalculates totals dynamically by summing incomes and expenses from the database. This live data interaction demonstrates how to keep UI and database in sync.

Handling UI with React Navigation and auto-sizing text for large numbers

To improve user experience, the app uses React Navigation for smooth screen transitions and segment controls. It also integrates the react-native-auto-size-text library to handle large numbers gracefully without breaking the layout.

For example, if a user enters a very large expense amount, the text automatically resizes to fit the UI, maintaining a clean design.

Managing data updates: adding, deleting, and recalculating totals

I show how to add new expenses with amount, description, emoji, and category selection. When saved, the data is inserted into SQLite and the UI updates instantly.

Deleting an expense is done by long pressing an item, which removes it from the database and updates the totals. Reloading the app preserves all data locally, demonstrating persistent storage.

Exporting and scaling options for the database and app

The app can scale to handle thousands of records by implementing pagination or exporting the SQLite database file. Users could back up or share their data by exporting the database.

For more complex needs, syncing the database to the cloud is possible but not covered here. I encourage exploring these options depending on your app’s requirements.

Resources

CourseReact Native course

Premium resourcePro Membership

Let's connect!

Had a win? Get featured on Code with Beto.Share your story