Skip to content

Conversation

@Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Jun 6, 2024

This PR introduces the ability to pass parameters from a client SDK to the sync rules. The idea is to specify parameters to the PowerSync connect method's options . Backend changes to support this are available here.

export const SystemProvider = ()=> {
  const [connector] = React.useState(new DemoConnector());
  const [powerSync] = React.useState(db);

  React.useEffect(() => {
  
    powerSync.init();
    powerSync.connect(connector, {
      params: { device_id: "276fca51-041e-4061-b7e3-3e2e699b40b4" }  // <- Specifying user parameters
    });
  }, [powerSync, connector]);

Parameters are available in the sync rules under user_parameters (alongside the already supported token_parameters).

For example:

bucket_definitions:
  user_lists:
    parameters: select id as list_id from lists where owner_id = user_parameters.device_id
    data:
      - SELECT * FROM lists where id = bucket.list_id

Testing

Verified values pull through via self-host project.

Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead pass the parameters when calling connect()?

The credentials are fetched at non-deterministic times, which can make it difficult to update the parameters.

@Chriztiaan
Copy link
Contributor Author

Could we instead pass the parameters when calling connect()?

The credentials are fetched at non-deterministic times, which can make it difficult to update the parameters.

Sounds good

@Chriztiaan Chriztiaan force-pushed the feature/user-parameters branch from 7f4f84c to 23d77f8 Compare June 10, 2024 13:49
@Chriztiaan Chriztiaan marked this pull request as ready for review June 10, 2024 14:03
@Chriztiaan
Copy link
Contributor Author

Chriztiaan commented Jun 10, 2024

@rkistner, I've updated the PR to use connect instead, also updated the PR description's example.

@Chriztiaan
Copy link
Contributor Author

Chriztiaan commented Jun 13, 2024

Deployed the service changes to staging and confirmed that the powersync-js react todo app works when providing the parameters when connection.

image image

@Chriztiaan Chriztiaan merged commit 590ee67 into main Jun 14, 2024
@Chriztiaan Chriztiaan deleted the feature/user-parameters branch June 14, 2024 14:09
@Chriztiaan Chriztiaan changed the title update: added user parameters to PowerSyncCredentials which are available in sync rules. update: added client parameters to PowerSyncCredentials which are available in sync rules. Jun 25, 2024
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