How to add a local database to your Expo app, in short
Use expo-sqlite. Install it with npx expo install expo-sqlite, then wrap your app (or your root layout) in <SQLiteProvider databaseName="app.db" onInit={migrateDbIfNeeded}>. Inside onInit you create your tables. Any screen below the provider calls const db = useSQLiteContext() and reads or writes with db.getAllAsync('SELECT * FROM notes') and db.runAsync('INSERT INTO notes (title) VALUES (?)', title). Expo's docs say the database is persisted across restarts of your app, so whatever the user saves is still there the next time they open it.
That is the whole core. The parts that decide whether it holds up after launch are schema versioning, parameter binding, and picking the right storage for each kind of data. Those are what most AI-generated database code skips, and they are what this guide covers.
Do you need a database, or just key-value storage?
Before you design tables, decide what you are storing. A lot of indie apps only need to remember a handful of settings, and a database is more than that job needs.
Picking local storage in an Expo app
| What you are storing | Use | Why |
|---|---|---|
| Settings, flags, last-opened tab, onboarding done | expo-sqlite/kv-store | Same API as AsyncStorage, plus sync methods. No schema to design. |
| Lists the user creates: notes, workouts, habits, journal entries | expo-sqlite tables | You need to filter, sort, count and update rows. |
| Login tokens, API secrets, anything sensitive | expo-secure-store | Stored in the platform keychain or keystore, not a plain file. |
| Data shared across devices or with other users | A backend such as Supabase, with SQLite as a local cache | A local database lives on one device only. |
My recommendation: if the user creates anything they would be upset to lose, or you will ever want to search or sort it, go straight to SQLite tables. Stuffing a growing JSON array into one key-value entry works for a week and then becomes the thing you have to migrate out of. If the data must follow the user to a new phone, you also need a backend; [how to set up Supabase with Expo](/blog/how-to-set-up-supabase-with-expo) covers that side.
Step 1: Install expo-sqlite and open a database
- Install: npx expo install expo-sqlite. Using expo install picks the version that matches your SDK.
- Import: import { SQLiteProvider, useSQLiteContext, type SQLiteDatabase } from 'expo-sqlite'.
- Wrap the app: <SQLiteProvider databaseName="app.db" onInit={migrateDbIfNeeded}> around your navigator. With Expo Router, that goes in app/_layout.tsx around the Stack or Tabs.
- Optional: add the useSuspense prop and put a React Suspense boundary above it to show a loading view until the database is ready.
If you need the database outside React, for example in a background task or a plain module, you can open it directly with const db = await SQLite.openDatabaseAsync('app.db') (or openDatabaseSync). Expo's docs show both styles. In a typical app the provider is cleaner, because every screen shares one connection and nothing queries before the tables exist.
Step 2: Create tables with a versioned migration
This is the step that saves you after launch. Your first version has a notes table. Version two adds a pinned column. Users who installed version one already have a database on their phone with the old shape, and an app update does not reset it. You need code that upgrades their existing database, step by step.
Expo's own example uses SQLite's built-in PRAGMA user_version for this. In migrateDbIfNeeded: read the current version with await db.getFirstAsync<{ user_version: number }>('PRAGMA user_version'). If it is 0, run execAsync with PRAGMA journal_mode = 'wal' and CREATE TABLE notes (id INTEGER PRIMARY KEY NOT NULL, title TEXT NOT NULL, created_at INTEGER NOT NULL). Then for each later version add another if block, such as if (currentDbVersion === 1) { ALTER TABLE notes ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0 }. At the end, set PRAGMA user_version to the latest number.
Expo's docs also recommend enabling WAL journal mode when you create a new database, for better performance in general, which is why it sits in the first migration.
Step 3: Read and write data safely
In a screen, call const db = useSQLiteContext() and use the method that matches the job. Expo's reference groups them like this:
The everyday expo-sqlite methods
| Method | Use it for | Example |
|---|---|---|
| runAsync | INSERT, UPDATE, DELETE | await db.runAsync('INSERT INTO notes (title, created_at) VALUES (?, ?)', title, Date.now()) |
| getFirstAsync | One row | await db.getFirstAsync<Note>('SELECT * FROM notes WHERE id = ?', id) |
| getAllAsync | All matching rows, for smaller result sets | await db.getAllAsync<Note>('SELECT * FROM notes ORDER BY created_at DESC') |
| getEachAsync | Walking a large result one row at a time | for await (const row of db.getEachAsync('SELECT * FROM notes')) { ... } |
| execAsync | Setup SQL and migrations only | await db.execAsync('PRAGMA foreign_keys = ON') |
runAsync returns lastInsertRowId and changes, which is how you get the id of the row you just created. Parameters can be passed as separate arguments, as an array, or as an object with named parameters like { $title: title }.
If you run the same insert many times in a loop, a prepared statement is faster to write and reason about: db.prepareAsync once, statement.executeAsync per row, and statement.finalizeAsync in a finally block. Expo's docs say to always finalize, and recommend try/finally to make sure it happens.
Transactions: the async trap
Group related writes (for example, deleting a folder and all its notes) in a transaction so either all of them happen or none do. expo-sqlite gives you db.withTransactionAsync(async () => { ... }).
The detail Expo's docs call out: because of how async/await works, any query that runs while that transaction is open is included in it, even a query from a different part of your app that happens to fire at the same moment. If the transaction then fails and rolls back, it can take that unrelated write with it. withExclusiveTransactionAsync exists to fix this: only the queries inside its scope function run in the transaction. Use it when other parts of the app may be writing at the same time.
Keeping screens in sync with the database
A list screen loads rows once in a useEffect. The user adds a note on another screen, comes back, and the list is stale. Three ways to handle it, from simplest up:
- Reload when the screen comes into focus. With Expo Router, useFocusEffect re-runs your query each time the user returns to the screen. This is enough for most apps.
- Update local state right after the write. After runAsync succeeds, push the new row into the list state yourself.
- Listen for changes. Open the database with enableChangeListener set to true, then subscribe with addDatabaseChangeListener, which reports the table name and row id of modified data. Expo's docs note the feature only works with that option enabled.
If you want typed tables and generated migrations instead of hand-written SQL, Expo's docs list Drizzle ORM as an integration that runs on top of expo-sqlite. It is a reasonable upgrade once you have several tables. For one or two tables I would stay with plain SQL, because it is one less thing for you and Claude Code to keep in step.
Look inside the database while you build
Per Expo's docs, expo-sqlite includes a built-in DevTools inspector that is enabled automatically in development. Press Shift + M in the Expo CLI terminal to open the dev tools menu, then choose Open expo-sqlite. It lets you browse tables, view and edit rows, run SQL, and export the database from your browser. Use it to confirm a migration actually added the column before you ship the update. If you run Expo from the Claude Code desktop app, ask Claude to start the dev server and tell you when it is ready, then open the menu from that terminal.
Encryption, web support and other edge cases
- Encryption: expo-sqlite supports SQLCipher on Android, iOS and macOS. Set useSQLCipher in the expo-sqlite config plugin and build again; Expo notes SQLCipher is not supported in Expo Go. After opening the database, set the key with PRAGMA key. Do not hardcode that key in your code; keep it in expo-secure-store.
- Web: expo-sqlite runs on web too, but Expo's docs say you must configure Metro for wasm files and serve the Cross-Origin-Embedder-Policy and Cross-Origin-Opener-Policy headers. If your app is iOS and Android only, skip this.
- Shipping a pre-filled database: pass assetSource={{ assetId: require('./assets/seed.db') }} to SQLiteProvider to start from an existing .db file.
- Sharing with a widget or extension on iOS: Expo documents putting the database in an App Group shared container, using Paths.appleSharedContainers from expo-file-system and the provider's directory prop. That pairs with [how to add a widget to your Expo app](/blog/how-to-add-a-widget-to-your-expo-app).
- Removing a database: deleteDatabaseAsync(name) deletes the file, which is handy for a reset-app option during testing.
Mistakes that break local databases in Expo
- Copying code from older tutorials that use SQLite.openDatabase and db.transaction(tx => tx.executeSql(...)). That is the old API: Expo's SDK 52 changelog says expo-sqlite/legacy has been removed. Use openDatabaseAsync or SQLiteProvider.
- Building SQL strings from user input instead of binding parameters.
- Running CREATE TABLE at random spots in screens instead of one versioned onInit migration.
- Editing a migration that already shipped instead of adding a new version.
- Storing tokens or passwords in SQLite or kv-store instead of expo-secure-store.
- Treating the local database as a backup. It lives on one device, so it does not follow the user to a new phone unless you sync it to a backend.
- Querying before the database is ready, which goes away when every screen uses the provider.
If your goal is that the app keeps working without a connection, the database is only one piece. The rest (showing an offline state, queueing writes) is in [how to add offline support to your Expo app](/blog/how-to-add-offline-support-to-your-expo-app).
Have Claude Code set it up for you
Open your project in the Claude Code desktop app and name the exact API and the migration pattern. Without that, the AI often reaches for the removed legacy API or scatters CREATE TABLE calls across screens. A prompt that covers it:
Then add a line to your [CLAUDE.md](/blog/claude-md-for-expo-apps) like "schema changes are a new numbered step in migrateDbIfNeeded; never edit a shipped migration; always bind parameters" so a later session does not break existing users' data. Before you submit an update that changes the schema, install the previous build, add data, then install the new one on top and check the data survived. That is the test that catches migration bugs, and it is worth doing before every [app update you submit to the App Store](/blog/how-to-submit-an-app-update-to-the-app-store).
The short version
To add a local database to your Expo app: install expo-sqlite, wrap the app in SQLiteProvider with an onInit migration keyed on PRAGMA user_version, and query from screens with useSQLiteContext, runAsync and getAllAsync using bound parameters. Use kv-store for small settings and expo-secure-store for secrets. Add a new migration step for every schema change, and test upgrades over an old install before you ship.
If you are building your first iOS app with Claude Code and Expo and want a second pair of eyes on it before App Review, bring it to App Store Launch Club. Members share their builds for feedback, and the [curriculum](/curriculum) covers the full path from first build to first users. Join at applaunchclub.co for $9 a month.
Short, practical drops on app ideas, validating fast, store listings, and passing app review. No spam, unsubscribe anytime.
Frequently asked questions
What is the best local database for an Expo app?
For most Expo apps, expo-sqlite. It is maintained by Expo, included in Expo Go, persists data across app restarts, and works on Android, iOS and web. Add Drizzle ORM on top if you want typed tables and generated migrations.
Does expo-sqlite work in Expo Go?
Yes, expo-sqlite is included in Expo Go. The exception is SQLCipher encryption, which Expo says is not supported in Expo Go and needs a build with the config plugin.
Should I use AsyncStorage or SQLite in Expo?
Use key-value storage for small settings and SQLite tables for lists of user data you need to sort, filter or update. expo-sqlite includes expo-sqlite/kv-store, a drop-in replacement for AsyncStorage, so you can do both with one library.
How do I update my database schema after the app is live?
Track the schema version with PRAGMA user_version and add a new numbered migration step in your onInit function for each change, for example an ALTER TABLE to add a column. Never edit a migration that already shipped.
Why does SQLite.openDatabase not work anymore?
That is the old API. Expo's SDK 52 changelog says expo-sqlite/legacy has been removed. Use openDatabaseAsync, openDatabaseSync, or the SQLiteProvider component with useSQLiteContext.
Is data in expo-sqlite saved when the user closes the app?
Yes. Expo's docs say the database is persisted across restarts of your app. It is stored on that device only, so it does not move to a new phone unless you sync it to a backend.
Can I encrypt an expo-sqlite database?
Yes, with SQLCipher. Enable useSQLCipher in the expo-sqlite config plugin, rebuild, and set the key with PRAGMA key right after opening the database. Keep the key in expo-secure-store, not in your code.
Last reviewed by David on October 18, 2026

