Skip to content

Commit 60a9662

Browse files
committed
docs(examples): update sync function examples for JSON return values
1 parent f0f35c3 commit 60a9662

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

examples/simple-todo-db/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ SELECT cloudsync_network_set_apikey('your-api-key-here');
168168

169169
-- Pull data from Device A - repeat until data is received
170170
SELECT cloudsync_network_sync();
171-
-- Keep calling until the function returns > 0 (indicating data was received)
171+
-- Check the "rowsReceived" field in the JSON result to see if data was received
172172
SELECT cloudsync_network_sync();
173173

174174
-- Verify data was synced
@@ -199,7 +199,7 @@ SELECT cloudsync_network_sync();
199199
```sql
200200
-- Get updates from Device B - repeat until data is received
201201
SELECT cloudsync_network_sync();
202-
-- Keep calling until the function returns > 0 (indicating data was received)
202+
-- Check the "rowsReceived" field in the JSON result to see if data was received
203203
SELECT cloudsync_network_sync();
204204

205205
-- View all tasks (should now include Device B's additions)
@@ -232,7 +232,7 @@ SELECT cloudsync_network_has_unsent_changes();
232232
-- When network returns, sync automatically resolves conflicts
233233
-- Repeat until all changes are synchronized
234234
SELECT cloudsync_network_sync();
235-
-- Keep calling until the function returns > 0 (indicating data was received/sent)
235+
-- Check the "rowsReceived" field in the JSON result to see if data was received/sent
236236
SELECT cloudsync_network_sync();
237237
```
238238

examples/to-do-app/components/SyncContext.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ export const SyncProvider = ({ children }) => {
5858

5959
const result = await Promise.race([queryPromise, timeoutPromise]);
6060

61-
if (result.rows && result.rows.length > 0 && result.rows[0]['cloudsync_network_check_changes()'] > 0) {
62-
console.log(`${result.rows[0]['cloudsync_network_check_changes()']} changes detected, triggering refresh`);
63-
// Defer refresh to next tick to avoid blocking current interaction
64-
setTimeout(() => triggerRefresh(), 0);
61+
const raw = result.rows?.[0]?.['cloudsync_network_check_changes()'];
62+
if (raw) {
63+
const { rowsReceived } = JSON.parse(raw);
64+
if (rowsReceived > 0) {
65+
console.log(`${rowsReceived} changes detected, triggering refresh`);
66+
// Defer refresh to next tick to avoid blocking current interaction
67+
setTimeout(() => triggerRefresh(), 0);
68+
}
6569
}
6670
} catch (error) {
6771
console.error('Error checking for changes:', error);

0 commit comments

Comments
 (0)