This is an example Expo app demonstrating the usage of @sqliteai/sqlite-sync-react-native with push notification sync mode.
Before running the example, you need to set up a SQLite Cloud database:
-
Create a SQLite Cloud account
- Go to SQLite Cloud Dashboard
- Create a new account or sign in
-
Create a new database
- Create a new project
- Create a new database in your project
-
Create the table
- In the SQLite Cloud dashboard, navigate to your database
- Execute the following SQL to create the demo table:
CREATE TABLE IF NOT EXISTS test_table ( id TEXT PRIMARY KEY NOT NULL, value TEXT, created_at TEXT DEFAULT CURRENT_TIMESTAMP );
-
Enable OffSync for the table
- Navigate to Databases > OffSync page in the dashboard
- Select
test_tableto enable synchronization - Learn more about OffSync configuration
-
Get your credentials
- Navigate to your database's Configuration tab
- Copy your Project ID, Database ID, and API Key
Follow the React Native environment setup guide to install Xcode and Android Studio.
-
Create configuration files
cd examples/sync-demo-expo cp .env.example .env -
Set up an Expo project (for push notifications)
- Go to Expo Dashboard
- Create a new account or sign in
- Create a new project and copy your Project ID
-
Fill in your
.envfile# SQLite Cloud credentials SQLITE_CLOUD_DATABASE_ID=db_xxxxxxxxxxxxxxxxxxxxxxxx ACCESS_TOKEN=your-jwt-here # or SQLITE_CLOUD_API_KEY=your-api-key-here DATABASE_NAME=sync-demo.db TABLE_NAME=test_table # Expo/EAS configuration EAS_PROJECT_ID=your-eas-project-id IOS_BUNDLE_IDENTIFIER=com.yourcompany.sqlitesyncexample ANDROID_PACKAGE=com.yourcompany.sqlitesyncexample
Note: The
TABLE_NAMEmust match the table you created in SQLite Cloud and enabled for OffSync. Provide eitherACCESS_TOKENfor user-level auth/RLS orSQLITE_CLOUD_API_KEYif you are not using RLS.
Push notifications enable real-time sync — your app receives instant updates when data changes in the cloud. Without push notifications, the library falls back to polling mode.
EAS will guide you through creating/uploading an APNs key. See the Expo Push Notifications setup guide for detailed instructions.
eas credentials -p ios- Go to Firebase Console
- Create a new project (or use an existing one)
- Add an Android app with your package name (matching
ANDROID_PACKAGEin.env) - Download
google-services.jsonand place it in this directory (examples/sync-demo-expo/) - Run
eas credentials -p androidto configure FCM credentials
If you have Expo enhanced security enabled, you need to provide your Expo access token so that SQLite Cloud can send push notifications to your devices.
- Go to Expo Access Tokens settings
- Generate a new access token (or use an existing one)
- Open the SQLite Cloud Dashboard
- Navigate to your database > OffSync > Configuration tab
- Under the Push Notifications section, paste your Expo access token in the Access Token field and click Save
Note: The access token is only required if you have Expo enhanced security enabled. Without it, push notifications work out of the box. The access token adds an extra layer of security to prevent unauthorized push notifications.
On the SQLite Cloud Dashboard (OffSync > Configuration), check:
- Status: Should show "Working"
- Access Token: Should show "Configured" (if you added one)
# From repository root
yarn installPush notifications require a real device. They do not work on simulators/emulators.
From the repository root:
yarn expo:ios:device # Build library + run iOS
yarn expo:android:device # Build library + run AndroidThe demo app demonstrates:
- SQLiteSyncProvider - Creates a local SQLite database that syncs with the cloud
- Push notification sync - Uses
expo-notificationsfor real-time sync triggers - Reactive queries - Uses
useSqliteSyncQueryfor automatic UI updates - Row-level notifications - Uses
useOnTableUpdatefor change tracking - Manual sync - Uses
useTriggerSqliteSyncfor on-demand sync - Background sync callback - Uses
registerBackgroundSyncCallbackfor background notifications
Test Push Notification Sync:
- Run the app on a real device (push notifications don't work on simulators)
- Grant push notification permissions when prompted
- Add data from the SQLite Cloud dashboard
- Watch the app sync instantly via push notification
Test Permission Denial Fallback:
- Deny push notification permissions when prompted
- The app automatically falls back to polling mode
- Data still syncs, just on a polling interval instead of instantly