Skip to content

Commit 6d3cb2e

Browse files
authored
Update demos to use sync streams (#878)
1 parent 0917045 commit 6d3cb2e

20 files changed

Lines changed: 99 additions & 93 deletions

File tree

demos/django-react-native-todolist/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ Create a new PowerSync instance, connecting to the database of the Supabase proj
5858
Then deploy the following sync rules:
5959

6060
```yaml
61-
bucket_definitions:
61+
config:
62+
edition: 3
63+
64+
streams:
6265
user_lists:
63-
# Separate bucket per todo list
64-
parameters: select id as list_id from lists where owner_id = request.user_id()
65-
data:
66-
- select * from lists
67-
- select * from todos
66+
queries:
67+
- SELECT * FROM lists WHERE owner_id = auth.user_id()
68+
- SELECT todos.* FROM todos JOIN lists ON todos.list_id = lists.id WHERE lists.owner_id = auth.user_id()
6869
```
6970
7071
#### Configure The App

demos/nuxt-supabase-todolist/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ This demo can be started with local PowerSync and Supabase services.
4646
docker run \
4747
-p 6060:6060 \
4848
-e POWERSYNC_CONFIG_B64=$(base64 -i ./powersync.yaml) \
49-
-e POWERSYNC_SYNC_RULES_B64=$(base64 -i ./sync-rules.yaml) \
49+
-e POWERSYNC_SYNC_RULES_B64=$(base64 -i ./sync-config.yaml) \
5050
--env-file ./.env \
5151
--network supabase_network_nuxt-supabase-todolist \
5252
--name powersync-nuxt journeyapps/powersync-service:latest
@@ -87,7 +87,7 @@ You can use either PowerSync Cloud or self-host PowerSync:
8787
- **PowerSync Cloud**: [Create a new project on the PowerSync dashboard](https://dashboard.powersync.com) and connect it to your Supabase database using the `powersync_role` credentials created in step 2.
8888
- **Self-hosting**: Follow the [self-hosting guide](https://docs.powersync.com/self-hosting/getting-started) to deploy your own PowerSync instance.
8989

90-
The sync rules for this demo are provided in [`sync-rules.yaml`](sync-rules.yaml) in this directory.
90+
The sync streams for this demo are provided in [`sync-config.yaml`](sync-config.yaml) in this directory.
9191

9292
### 5. Set up local environment variables
9393

@@ -131,7 +131,7 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to try out
131131
├── db/
132132
│ └── seed.sql # Database setup SQL
133133
├── powersync.yaml # PowerSync server configuration
134-
├── sync-rules.yaml # PowerSync sync rules
134+
├── sync-config.yaml # PowerSync sync streams
135135
└── nuxt.config.ts # Nuxt configuration
136136
```
137137

demos/nuxt-supabase-todolist/pages/login.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<UContainer class="h-[calc(100vh-var(--ui-header-height))] flex items-center justify-center px-4">
33
<UPageCard class="max-w-sm w-full">
4-
<UAuthForm :title="sign === 'in' ? 'Login' : 'Sign up'" icon="i-lucide-user" :fields="fields" @submit="onSubmit">
4+
<UAuthForm :title="isSignIn ? 'Login' : 'Sign up'" icon="i-lucide-user" :fields="fields" @submit="onSubmit">
55
<template #description>
6-
{{ sign === 'up' ? "Don't have an account?" : 'Already have an account?' }}
7-
<UButton variant="link" class="p-0" @click="sign = sign === 'up' ? 'in' : 'up'">
8-
{{ sign === 'in' ? 'Sign In' : 'Sign Up' }} </UButton
6+
{{ isSignIn ? "Don't have an account?" : 'Already have an account?' }}
7+
<UButton variant="link" class="p-0" @click="toggleSign">
8+
{{ isSignIn ? 'Sign Up' : 'Sign In' }} </UButton
99
>.
1010
</template>
1111
</UAuthForm>
@@ -20,6 +20,8 @@ const user = useSupabaseUser();
2020
const toast = useToast();
2121
2222
const sign = ref<'in' | 'up'>('in');
23+
const isSignIn = computed(() => sign.value === 'in');
24+
const toggleSign = () => (sign.value = sign.value === 'in' ? 'up' : 'in');
2325
2426
watchEffect(() => {
2527
if (user.value) {

demos/nuxt-supabase-todolist/plugins/powersync.client.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import {
22
AppSchemaWithDiagnostics,
33
} from '~/powersync/AppSchema'
44
import { SupabaseConnector } from '~/powersync/SuperbaseConnector'
5-
import { SyncClientImplementation } from '@powersync/web'
6-
7-
85
export default defineNuxtPlugin({
96
async setup(nuxtApp) {
107
const db = new NuxtPowerSyncDatabase({
@@ -18,9 +15,7 @@ export default defineNuxtPlugin({
1815

1916
await db.init()
2017

21-
await db.connect(connector, {
22-
clientImplementation: SyncClientImplementation.RUST,
23-
})
18+
await db.connect(connector)
2419

2520
const plugin = createPowerSyncPlugin({ database: db })
2621

demos/nuxt-supabase-todolist/powersync.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ storage:
1313
sslmode: disable
1414
# sslmode: verify-full
1515

16-
sync_rules:
17-
path: ./sync-rules.yaml
16+
sync_config:
17+
path: ./sync-config.yaml
1818

1919
port: !env PS_PORT
2020

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
config:
2+
edition: 3
3+
4+
streams:
5+
user_tasks:
6+
auto_subscribe: true
7+
queries:
8+
- SELECT * FROM tasks WHERE user_id = auth.user_id()

demos/nuxt-supabase-todolist/sync-rules.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

demos/react-multi-client/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ The RLS rules defined in the `database.sql` script are setup to only allow the a
3838

3939
Follow the [Connect PowerSync to Your Supabase](https://docs.powersync.com/integration-guides/supabase-+-powersync#connect-powersync-to-your-supabase) section.
4040

41-
### 5. Create Sync Rules on PowerSync
41+
### 5. Create Sync Streams on PowerSync
4242

43-
Create sync rules by following the [Configure Sync Rules](https://docs.powersync.com/integration-guides/supabase-+-powersync#configure-sync-rules) section.
44-
The sync rules for this demo are defined in [`sync-rules.yaml`](sync-rules.yaml) in this directory. Copy its contents and paste it into the 'sync-rules.yaml' file in the Dashboard as described in the guide.
43+
Create sync streams by following the [Configure Sync Streams](https://docs.powersync.com/integration-guides/supabase-+-powersync#configure-sync-streams) section.
44+
The sync streams for this demo are defined in [`sync-config.yaml`](sync-config.yaml) in this directory. Copy its contents and paste it into the sync streams editor in the Dashboard.
4545

4646
### 6. Set up local environment variables
4747

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
config:
2+
edition: 3
3+
4+
streams:
5+
user_lists:
6+
auto_subscribe: true
7+
queries:
8+
- SELECT * FROM pebbles WHERE user_id = auth.user_id()

demos/react-multi-client/sync-rules.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)