Skip to content

Commit e13f235

Browse files
committed
docs(examples): update example for the new managedDatabaseId arg for cloudsync_network_init
1 parent 3b426cb commit e13f235

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

examples/simple-todo-db/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ SELECT cloudsync_is_enabled('tasks');
104104

105105
```sql
106106
-- Configure connection to SQLite Cloud
107-
-- Replace with your actual connection string from Step 1.3
108-
SELECT cloudsync_network_init('sqlitecloud://your-project-id.sqlite.cloud/todo_app.sqlite');
107+
-- Replace with your managedDatabaseId from the OffSync page on the SQLiteCloud dashboard
108+
SELECT cloudsync_network_init('your-managed-database-id');
109109

110110
-- Configure authentication:
111111
-- Set your API key from Step 1.3
@@ -163,7 +163,7 @@ CREATE TABLE IF NOT EXISTS tasks (
163163
SELECT cloudsync_init('tasks');
164164

165165
-- Connect to the same cloud database
166-
SELECT cloudsync_network_init('sqlitecloud://your-project-id.sqlite.cloud/todo_app.sqlite');
166+
SELECT cloudsync_network_init('your-managed-database-id');
167167
SELECT cloudsync_network_set_apikey('your-api-key-here');
168168

169169
-- Pull data from Device A - repeat until data is received

examples/sport-tracker-app/.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Copy from from the SQLite Cloud Dashboard
2-
# eg: sqlitecloud://myhost.cloud:8860/my-remote-database.sqlite
3-
VITE_SQLITECLOUD_CONNECTION_STRING=
1+
# Copy the managedDatabaseId from the OffSync page on the SQLiteCloud Dashboard
2+
VITE_SQLITECLOUD_MANAGED_DATABASE_ID=
43
# The database name
54
# eg: my-remote-database.sqlite
65
VITE_SQLITECLOUD_DATABASE=

examples/sport-tracker-app/src/db/sqliteSyncOperations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ export const initSQLiteSync = (db: any) => {
9090
// ...or initialize all tables at once
9191
// db.exec('SELECT cloudsync_init("*");');
9292

93-
// Initialize SQLite Sync with the SQLite Cloud Connection String.
94-
// On the SQLite Cloud Dashboard, enable OffSync (SQLite Sync)
95-
// on the remote database and copy the Connection String.
93+
// Initialize SQLite Sync with the managedDatabaseId.
94+
// On the SQLite Cloud Dashboard, enable OffSync (SQLite Sync)
95+
// on the remote database and copy the managedDatabaseId.
9696
db.exec(
9797
`SELECT cloudsync_network_init('${
98-
import.meta.env.VITE_SQLITECLOUD_CONNECTION_STRING
98+
import.meta.env.VITE_SQLITECLOUD_MANAGED_DATABASE_ID
9999
}')`
100100
);
101101
};

examples/to-do-app/.env.example

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Copy from the SQLite Cloud Dashboard
2-
# eg: sqlitecloud://myhost.cloud:8860/my-remote-database.sqlite?apikey=myapikey
3-
CONNECTION_STRING = "<your-connection-string>"
4-
API_TOKEN =
1+
# Copy from the OffSync page on the SQLiteCloud Dashboard
2+
MANAGED_DATABASE_ID = "<your-managed-database-id>"
3+
API_TOKEN =

examples/to-do-app/hooks/useCategories.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect } from 'react'
22
import { Platform } from 'react-native';
33
import { db } from "../db/dbConnection";
4-
import { ANDROID_CONNECTION_STRING, CONNECTION_STRING, API_TOKEN } from "@env";
4+
import { ANDROID_MANAGED_DATABASE_ID, MANAGED_DATABASE_ID, API_TOKEN } from "@env";
55
import { getDylibPath } from "@op-engineering/op-sqlite";
66
import { randomUUID } from 'expo-crypto';
77
import { useSyncContext } from '../components/SyncContext';
@@ -72,11 +72,11 @@ const useCategories = () => {
7272
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', ['work', 'Work'])
7373
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', ['personal', 'Personal'])
7474

75-
if ((ANDROID_CONNECTION_STRING || CONNECTION_STRING) && API_TOKEN) {
76-
await db.execute(`SELECT cloudsync_network_init('${Platform.OS == 'android' && ANDROID_CONNECTION_STRING ? ANDROID_CONNECTION_STRING : CONNECTION_STRING}');`);
75+
if ((ANDROID_MANAGED_DATABASE_ID || MANAGED_DATABASE_ID) && API_TOKEN) {
76+
await db.execute(`SELECT cloudsync_network_init('${Platform.OS == 'android' && ANDROID_MANAGED_DATABASE_ID ? ANDROID_MANAGED_DATABASE_ID : MANAGED_DATABASE_ID}');`);
7777
await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`)
7878
} else {
79-
throw new Error('No valid CONNECTION_STRING or API_TOKEN provided, cloudsync_network_init will not be called');
79+
throw new Error('No valid MANAGED_DATABASE_ID or API_TOKEN provided, cloudsync_network_init will not be called');
8080
}
8181

8282
db.execute('SELECT cloudsync_network_sync(100, 10);')

0 commit comments

Comments
 (0)