From 79710fc93d7fb4bf1e8ad8b2390a5e3cca072a5c Mon Sep 17 00:00:00 2001 From: benitav Date: Tue, 20 Aug 2024 15:17:36 +0200 Subject: [PATCH] New sync rules parameter syntax --- demos/django-react-native-todolist/README.md | 2 +- demos/react-multi-client/sync-rules.yaml | 2 +- .../sync-rules.yml | 16 ++++++++-------- demos/react-native-supabase-todolist/README.md | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/demos/django-react-native-todolist/README.md b/demos/django-react-native-todolist/README.md index d47f3840..6326261e 100644 --- a/demos/django-react-native-todolist/README.md +++ b/demos/django-react-native-todolist/README.md @@ -61,7 +61,7 @@ Then deploy the following sync rules: bucket_definitions: user_lists: # Separate bucket per todo list - parameters: select id as list_id from lists where owner_id = token_parameters.user_id + parameters: select id as list_id from lists where owner_id = request.user_id() data: - select * from lists - select * from todos diff --git a/demos/react-multi-client/sync-rules.yaml b/demos/react-multi-client/sync-rules.yaml index 5e0fe43c..e5033f46 100644 --- a/demos/react-multi-client/sync-rules.yaml +++ b/demos/react-multi-client/sync-rules.yaml @@ -1,5 +1,5 @@ bucket_definitions: user_lists: - parameters: SELECT token_parameters.user_id as user_id + parameters: SELECT request.user_id() as user_id data: - SELECT * FROM pebbles WHERE user_id = bucket.user_id diff --git a/demos/react-native-supabase-group-chat/sync-rules.yml b/demos/react-native-supabase-group-chat/sync-rules.yml index 276c95f4..56f28f65 100644 --- a/demos/react-native-supabase-group-chat/sync-rules.yml +++ b/demos/react-native-supabase-group-chat/sync-rules.yml @@ -1,6 +1,6 @@ bucket_definitions: user: - parameters: select token_parameters.user_id as user_id + parameters: select request.user_id() as user_id data: - select * from profiles where id = bucket.user_id - select * from memberships where profile_id = bucket.user_id @@ -10,27 +10,27 @@ bucket_definitions: - select * from messages where recipient_id = bucket.user_id AND messages.sent_at IS NOT NULL - select * from groups where owner_id = bucket.user_id contacts: - parameters: select profile_id from contacts where owner_id = token_parameters.user_id + parameters: select profile_id from contacts where owner_id = request.user_id() data: - select * from profiles where id = bucket.profile_id groups: parameters: - - select id as group_id from groups where owner_id = token_parameters.user_id - - select group_id from memberships where profile_id = token_parameters.user_id + - select id as group_id from groups where owner_id = request.user_id() + - select group_id from memberships where profile_id = request.user_id() data: - select * from groups where id = bucket.group_id - select * from messages where group_id = bucket.group_id AND messages.sent_at IS NOT NULL - select * from memberships where group_id = bucket.group_id group_draft_messages: parameters: - - select id as group_id, owner_id as user_id from groups where owner_id = token_parameters.user_id - - select group_id, profile_id as user_id from memberships where profile_id = token_parameters.user_id + - select id as group_id, owner_id as user_id from groups where owner_id = request.user_id() + - select group_id, profile_id as user_id from memberships where profile_id = request.user_id() data: - select * from messages where group_id = bucket.group_id AND sender_id = bucket.user_id AND messages.sent_at IS NULL chats: parameters: - - select recipient_id as partner_id from messages where sender_id = token_parameters.user_id - - select sender_id as partner_id from messages where recipient_id = token_parameters.user_id + - select recipient_id as partner_id from messages where sender_id = request.user_id() + - select sender_id as partner_id from messages where recipient_id = request.user_id() data: - select id, id as profile_id from profiles as chats where id = bucket.partner_id - select * from profiles where id = bucket.partner_id diff --git a/demos/react-native-supabase-todolist/README.md b/demos/react-native-supabase-todolist/README.md index 3cdfb7cd..0fcf7521 100644 --- a/demos/react-native-supabase-todolist/README.md +++ b/demos/react-native-supabase-todolist/README.md @@ -27,7 +27,7 @@ Then deploy the following sync rules: bucket_definitions: user_lists: # Separate bucket per todo list - parameters: select id as list_id from lists where owner_id = token_parameters.user_id + parameters: select id as list_id from lists where owner_id = request.user_id() data: - select * from lists where id = bucket.list_id - select * from todos where list_id = bucket.list_id