Skip to content

Conversation

DominicGBauer
Copy link
Contributor

@DominicGBauer DominicGBauer commented Sep 23, 2024

Description

Add params option in connect method of PowerSyncDatabase to allow users to set sync rules parameters from the client. To ensure type safety a new sealed class JsonParam was created so that params accepts a Map<String, JsonParam?>? which will prevent users erroneously including invalid parameters. Example usage:

    val params = JsonParam.Map(
          mapOf(
              "name" to JsonParam.String("John Doe"),
              "age" to JsonParam.Number(30),
              "isStudent" to JsonParam.Boolean(false)
         )
     )

   connect(
         connector = connector,
         crudThrottleMs = 2000L,
         retryDelayMs = 10000L,
         params = params
     )

Testing

I set new sync rules

bucket_definitions:
  list_buckets:
    accept_potentially_dangerous_queries: true
    parameters: select request.parameters() ->> 'listId' as list_id
    data:
      - SELECT * FROM lists where id = bucket.list_id

and passed a listId from the client side

db.connect(supabase, params = mapOf("listId" to "c3a57c9a-06e0-490a-9003-66cd838f7bde".toJsonParam()))
Screen.Recording.2024-09-23.at.11.50.23.mov

Chriztiaan
Chriztiaan previously approved these changes Oct 1, 2024
@DominicGBauer DominicGBauer requested a review from mugikhan October 1, 2024 12:32
@DominicGBauer DominicGBauer merged commit d4b7725 into main Oct 3, 2024
3 checks passed
@DominicGBauer DominicGBauer deleted the feat/add-client-sync-rule-parameters branch October 3, 2024 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants