This is an example bare React Native app (without Expo) demonstrating the usage of @sqliteai/sqlite-sync-react-native.
This example ensures that the library works correctly in both Expo and non-Expo projects.
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 Database ID
- Generate or copy an Access Token for the user/session you want to test with
Follow the React Native environment setup guide to install Xcode and Android Studio.
-
Create a
.envfilecd examples/sync-demo-bare cp .env.example .env -
Fill in your configuration in the
.envfile:SQLITE_CLOUD_DATABASE_ID=db_xxxxxxxxxxxxxxxxxxxxxxxx DATABASE_NAME=sync-demo.db TABLE_NAME=test_table
Note: The
TABLE_NAMEmust match the table name you created in SQLite Cloud and enabled for OffSync. -
Set your auth credential in
examples/sync-demo-bare/.env:ACCESS_TOKEN=your_jwt_here # or use SQLITE_CLOUD_API_KEY=your_api_key_here
The bare example reads env values from
.envviareact-native-dotenv, so after changing.envyou should reset Metro cache before rerunning the app.
# From repository root
yarn installFrom the repository root:
yarn bare:metro:reset # Terminal 1: start Metro with cache reset
yarn bare:ios # Terminal 2: clean + build + run iOS
# Android
yarn bare:metro:reset # Terminal 1: same Metro command
yarn bare:android # Terminal 2: clean + build + run AndroidThe demo app demonstrates:
- SQLiteSyncProvider - Creates a local SQLite database that syncs with the cloud
- Adaptive polling sync - Automatically syncs at intelligent intervals
- Reactive queries - Uses
useSqliteSyncQueryfor automatic UI updates - Row-level notifications - Uses
useOnTableUpdatefor change tracking - Manual sync - Uses
useTriggerSqliteSyncfor on-demand sync
Test Real-Time Sync:
- Open the app on multiple devices or alongside the SQLite Cloud dashboard to see real-time synchronization in action!
Test Offline Mode:
- Turn off your internet connection
- Add entries in the app (they'll be saved locally)
- Turn your internet back on
- Watch the sync automatically happen