Skip to content

Commit 98838f8

Browse files
authored
Various polish (#214)
* add expo go new app instructions * add node.js attachment community project * Add compact action to list * Rather follow existing examples around pending lists * Wording * Add sync rules as a next step
1 parent a0c611b commit 98838f8

File tree

4 files changed

+96
-11
lines changed

4 files changed

+96
-11
lines changed

client-sdk-references/react-native-and-expo/expo-go-support.mdx

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,102 @@ A development package for PowerSync which uses SQL.js to provide a pure JavaScri
1717

1818
## Usage
1919

20+
<Tabs>
21+
<Tab title="New App">
22+
23+
### Quickstart
24+
25+
1. Create a new Expo app:
26+
```bash
27+
npx create-expo-app@latest my-app
28+
```
29+
30+
2. Navigate to your app directory and start the development server:
31+
```bash
32+
cd my-app && npm run ios
33+
```
34+
35+
3. In a new terminal tab, install PowerSync dependencies:
36+
```bash
37+
npm install @powersync/react-native @powersync/adapter-sql-js
38+
```
39+
40+
4. Replace the code in `app/(tabs)/index.tsx` with:
41+
42+
```tsx app/(tabs)/index.tsx
43+
import { SQLJSOpenFactory } from "@powersync/adapter-sql-js";
44+
import { PowerSyncDatabase, Schema } from "@powersync/react-native";
45+
import { useEffect, useState } from "react";
46+
import { Text } from "react-native";
47+
48+
export const powerSync = new PowerSyncDatabase({
49+
schema: new Schema({}), // todo: define the schema - see Next Steps below
50+
database: new SQLJSOpenFactory({
51+
dbFilename: "example.db",
52+
}),
53+
});
54+
55+
export default function HomeScreen() {
56+
const [version, setVersion] = useState<string | null>(null);
57+
58+
useEffect(() => {
59+
powerSync.get("select powersync_rs_version();").then((r) => {setVersion(JSON.stringify(r))});
60+
}, []);
61+
62+
return (
63+
<>{version && <Text style={{fontSize: 24, fontWeight: 'bold'}}>PowerSync Initialized - {version}</Text>}</>
64+
);
65+
}
66+
```
67+
68+
</Tab>
69+
<Tab title="Existing App">
70+
71+
1. Install the SQL.js adapter:
2072
```bash
2173
npm install @powersync/adapter-sql-js
2274
```
2375

24-
```js SystemProvider.tsx
76+
2. Set up PowerSync by using the Sql.js factory:
77+
78+
```tsx SystemProvider.tsx
2579
import { SQLJSOpenFactory } from "@powersync/adapter-sql-js";
26-
import { PowerSyncDatabase } from "@powersync/react-native";
80+
import { PowerSyncDatabase, Schema } from "@powersync/react-native";
81+
import { useEffect, useState } from "react";
82+
import { Text } from "react-native";
2783

2884
export const powerSync = new PowerSyncDatabase({
29-
schema: AppSchema,
85+
schema: new Schema({}), // todo: define the schema - see Next Steps below
3086
database: new SQLJSOpenFactory({
3187
dbFilename: "example.db",
3288
}),
3389
});
90+
91+
export default function HomeScreen() {
92+
const [version, setVersion] = useState<string | null>(null);
93+
94+
useEffect(() => {
95+
powerSync.get("select powersync_rs_version();").then((r) => {setVersion(JSON.stringify(r))});
96+
}, []);
97+
98+
return (
99+
<>{version && <Text style={{fontSize: 24, fontWeight: 'bold'}}>PowerSync Initialized - {version}</Text>}</>
100+
);
101+
}
34102
```
35103

36-
### Data Persistence
104+
</Tab>
105+
</Tabs>
106+
107+
## Next Steps
108+
109+
After adding PowerSync to your app:
110+
111+
1. [**Define what data to sync by setting up Sync Rules**](/usage/sync-rules)
112+
2. [**Implement your SQLite client schema**](/client-sdk-references/react-native-and-expo#1-define-the-schema)
113+
3. [**Connect to PowerSync and your backend**](/client-sdk-references/react-native-and-expo#3-integrate-with-your-backend)
114+
115+
## Data Persistence
37116

38117
The default version of this adapter uses in-memory persistence, but you can specify your own `persister` option to the open factory.
39118
See an example in the package [README](https://www.npmjs.com/package/@powersync/adapter-sql-js).

resources/demo-apps-example-projects.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ This page showcases example projects organized by platform and backend technolog
148148
</Accordion>
149149

150150
<Accordion title="Notable Community Projects" icon="people-carry-box">
151+
<Note>
152+
This is a list of projects we've spotted from community members 🙌 These projects haven't necessarily been vetted by us.
153+
</Note>
151154
#### Custom Backends
152155

153156
* Laravel Backend
@@ -171,6 +174,8 @@ This page showcases example projects organized by platform and backend technolog
171174
* Expo Web Integration
172175
* https://github.com/ImSingee/powersync-web-workers
173176
* Note: Our [React Native Web support](/client-sdk-references/react-native-and-expo/react-native-web-support) now eliminates the need to patch the `@powersync/web` module
177+
* Attachments library for Node.js
178+
* https://www.npmjs.com/package/@muhammedv/powersync-attachments-for-node
174179
</Accordion>
175180
</AccordionGroup>
176181

usage/tools/powersync-dashboard.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The various actions available in your project are accessible via the Command Pal
8181
- **Compare deployed sync rules** -\> Compare the [sync rules](/usage/sync-rules) as defined in your `sync-rules.yaml` file with those deployed to an instance.
8282
- **Save changes** -\> Save changes to files as a revision when in **Basic Revisions** version control mode (see _Version Control_ below)
8383
- Or **Commit changes** -\> Commit changes to files when in **Advanced Git** version control mode.
84+
- **Compact buckets** -\> Manually [compact](/usage/lifecycle-maintenance/compacting-buckets) and optionally [defragment](/usage/lifecycle-maintenance/compacting-buckets#defragmenting) sync buckets of an instance.
8485
- **Create Personal Access Token** -\> Create an access token scoped to your user, which is needed for the [CLI](/usage/tools/cli).
8586
- **Rename project** -\> Rename your PowerSync project.
8687

usage/use-case-examples/watch-queries.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,15 @@ This class provides advanced features:
403403
404404
```javascript
405405
// Create a shared query instance
406-
const sharedTodosQuery = db.query({ sql: 'SELECT * FROM todos WHERE list_id = ?', parameters: [listId] }).watch();
406+
const sharedListsQuery = db.query({ sql: 'SELECT * FROM lists WHERE state = ?', parameters: ['pending'] }).watch();
407407

408408
// Multiple components can listen to the same query
409-
const dispose1 = sharedTodosQuery.registerListener({
410-
onData: (data) => updateTodosList(data)
409+
const dispose1 = sharedListsQuery.registerListener({
410+
onData: (data) => updatePendingListsDisplay(data)
411411
});
412412

413-
const dispose2 = sharedTodosQuery.registerListener({
414-
onData: (data) => updateTodosCount(data.length)
413+
const dispose2 = sharedListsQuery.registerListener({
414+
onData: (data) => updatePendingListsCount(data.length)
415415
});
416416
```
417417
@@ -421,8 +421,8 @@ Update query parameters to affect all subscribers of the query:
421421
422422
```javascript
423423
// Updates to query parameters can be performed in a single place, affecting all subscribers
424-
watch.updateSettings({
425-
query: new GetAllQuery({ sql: `SELECT * FROM todos OFFSET ? LIMIT 100`, parameters: [newOffset] })
424+
sharedListsQuery.updateSettings({
425+
query: { sql: 'SELECT * FROM lists WHERE state = ?', parameters: ['canceled'] }
426426
});
427427
```
428428

0 commit comments

Comments
 (0)