This is an example Expo app demonstrating the usage of @sqliteai/sqlite-sync-react-native.
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 Connection String (format:
sqlitecloud://your-host.sqlite.cloud:8860/your-database) - Copy your API Key
Follow the React Native environment setup guide to install Xcode and Android Studio.
-
Create a
.envfilecd examples/sync-demo cp .env.example .env -
Fill in your credentials in the
.envfile:SQLITE_CLOUD_CONNECTION_STRING=sqlitecloud://your-host.sqlite.cloud:8860/your-database SQLITE_CLOUD_API_KEY=your-api-key-here 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.
# From repository root
yarn install
yarn prepare
# Install example dependencies
cd examples/sync-demo
yarn installcd examples/sync-demo
npx expo prebuild --platform ios --clean
cd ios && pod install && cd ..
npx expo run:ioscd examples/sync-demo
npx expo prebuild --platform android --clean
npx expo run:androidThe demo app:
- Creates a local SQLite database that syncs with the cloud
- Allows you to add text entries that are automatically synced
- Displays sync status and last sync time
- Auto-reloads data when changes are received
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 and changes appear in the cloud!