Skip to content

Commit 4ca1bdf

Browse files
committed
fix(examples): replace connection strings with new database id configurations
1 parent 604f25e commit 4ca1bdf

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

examples/simple-todo-db/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ Before using the local CLI, you need to set up your cloud database:
2020
2. Name your database (e.g., "todo_app.sqlite")
2121
3. Click **"Create"**
2222

23-
### 1.3 Get Connection Details
24-
1. Copy the **Connection String** (format: `sqlitecloud://projectid.sqlite.cloud/database.sqlite`)
23+
### 1.3 Enable OffSync
24+
1. Click the **OffSync** button next to your database, then **Enable OffSync** and confirm with the **Enable** button
25+
2. In the **Configuration** tab copy the **Database ID** (format: `db_*`)
26+
27+
### 1.4 Get Auth Details
28+
1. In your project dashboard, click **Settings**, then **API Keys**
2529
2. Copy an **API Key**
2630

27-
### 1.4 Configure Row-Level Security (Optional)
31+
### 1.5 Configure Row-Level Security (Optional)
2832
1. In your database dashboard, go to **"Security"****"Row-Level Security"**
2933
2. Enable RLS for tables you want to secure
3034
3. Create policies to control user access (e.g., users can only see their own tasks)
@@ -104,11 +108,11 @@ SELECT cloudsync_is_enabled('tasks');
104108

105109
```sql
106110
-- Configure connection to SQLite Cloud
107-
-- Replace with your managedDatabaseId from the OffSync page on the SQLiteCloud dashboard
111+
-- Replace with your managedDatabaseId from the OffSync page on the SQLiteCloud dashboard from Step 1.3
108112
SELECT cloudsync_network_init('your-managed-database-id');
109113

110114
-- Configure authentication:
111-
-- Set your API key from Step 1.3
115+
-- Set your API key from Step 1.4
112116
SELECT cloudsync_network_set_apikey('your-api-key-here');
113117
-- Or use token authentication (required for Row-Level Security)
114118
-- SELECT cloudsync_network_set_token('your_auth_token');

examples/to-do-app/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ cd MyApp
2424

2525
Rename the `.env.example` into `.env` and fill with your values.
2626

27-
> **⚠️ SECURITY WARNING**: This example puts database connection strings directly in `.env` files for demonstration purposes only. **Do not use this pattern in production.**
27+
> **⚠️ SECURITY WARNING**: This example puts database API Keys directly in `.env` files for demonstration purposes only. **Do not use this pattern in production.**
2828
>
2929
> **Why this is unsafe:**
30-
> - Connection strings contain sensitive credentials
30+
> - API Keys allow access to sensitive credentials
3131
> - Client-side apps expose all environment variables to users
3232
> - Anyone can inspect your app and extract database credentials
3333
>

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

Lines changed: 3 additions & 3 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_MANAGED_DATABASE_ID, MANAGED_DATABASE_ID, API_TOKEN } from "@env";
4+
import { 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,8 +72,8 @@ 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_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}');`);
75+
if (MANAGED_DATABASE_ID && API_TOKEN) {
76+
await db.execute(`SELECT cloudsync_network_init('${MANAGED_DATABASE_ID}');`);
7777
await db.execute(`SELECT cloudsync_network_set_token('${API_TOKEN}');`)
7878
} else {
7979
throw new Error('No valid MANAGED_DATABASE_ID or API_TOKEN provided, cloudsync_network_init will not be called');

examples/to-do-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqliteai/todoapp",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "An Expo template for building apps with the SQLite CloudSync extension",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)