Skip to content

Commit

Permalink
New sync rules parameter syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
benitav authored Aug 20, 2024
1 parent 7d04f74 commit 79710fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demos/django-react-native-todolist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion demos/react-multi-client/sync-rules.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions demos/react-native-supabase-group-chat/sync-rules.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion demos/react-native-supabase-todolist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 79710fc

Please sign in to comment.