Skip to content

Commit 673b5fa

Browse files
committed
fix(examples/to-do-app): missing dependencies, upgrade react-native, fix Android to use different connection string for localhost usage and replaced old cloudsync_init * apis with new one with explicit table names
1 parent c46c995 commit 673b5fa

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

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

Lines changed: 11 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 { CONNECTION_STRING, API_TOKEN } from "@env";
4+
import { ANDROID_CONNECTION_STRING, CONNECTION_STRING, API_TOKEN } from "@env";
55
import { getDylibPath } from "@op-engineering/op-sqlite";
66
import { randomUUID } from 'expo-crypto';
77
import { useSyncContext } from '../components/SyncContext';
@@ -65,12 +65,19 @@ const useCategories = () => {
6565
await db.execute('CREATE TABLE IF NOT EXISTS tags (uuid TEXT NOT NULL PRIMARY KEY, name TEXT, UNIQUE(name));')
6666
await db.execute('CREATE TABLE IF NOT EXISTS tasks_tags (uuid TEXT NOT NULL PRIMARY KEY, task_uuid TEXT, tag_uuid TEXT, FOREIGN KEY (task_uuid) REFERENCES tasks(uuid), FOREIGN KEY (tag_uuid) REFERENCES tags(uuid));')
6767

68-
await db.execute(`SELECT cloudsync_init('*');`);
68+
await db.execute(`SELECT cloudsync_init('tasks');`);
69+
await db.execute(`SELECT cloudsync_init('tags');`);
70+
await db.execute(`SELECT cloudsync_init('tasks_tags');`);
71+
6972
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', [randomUUID(), 'Work'])
7073
await db.execute('INSERT OR IGNORE INTO tags (uuid, name) VALUES (?, ?)', [randomUUID(), 'Personal'])
7174

72-
await db.execute(`SELECT cloudsync_network_init('${CONNECTION_STRING}');`);
73-
await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`)
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}');`);
77+
await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`)
78+
} else {
79+
throw new Error('No valid CONNECTION_STRING or API_TOKEN provided, cloudsync_network_init will not be called');
80+
}
7481

7582
db.execute('SELECT cloudsync_network_sync(100, 10);')
7683
getCategories()

examples/to-do-app/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
"url": "git+https://github.com/sqliteai/sqlite-sync.git"
88
},
99
"author": "SQLiteAI",
10-
"keywords": ["expo-template", "sqlite", "cloudsync", "todo", "sync", "react-native", "expo", "template"],
10+
"keywords": [
11+
"expo-template",
12+
"sqlite",
13+
"cloudsync",
14+
"todo",
15+
"sync",
16+
"react-native",
17+
"expo",
18+
"template"
19+
],
1120
"main": "expo/AppEntry.js",
1221
"scripts": {
1322
"start": "expo start",
@@ -24,10 +33,12 @@
2433
"@react-navigation/native": "^7.1.17",
2534
"@react-navigation/stack": "^7.4.7",
2635
"expo": "^53.0.22",
36+
"expo-asset": "^12.0.12",
37+
"expo-constants": "^18.0.13",
2738
"expo-crypto": "~14.1.5",
2839
"expo-status-bar": "~2.2.3",
2940
"react": "19.0.0",
30-
"react-native": "0.79.5",
41+
"react-native": "0.79.6",
3142
"react-native-gesture-handler": "~2.24.0",
3243
"react-native-paper": "5.14.5",
3344
"react-native-picker-select": "^9.3.1",

0 commit comments

Comments
 (0)