Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watched LEFT JOIN query does not update on local-only table #16

Closed
Manrich121 opened this issue Oct 25, 2023 · 2 comments
Closed

Watched LEFT JOIN query does not update on local-only table #16

Manrich121 opened this issue Oct 25, 2023 · 2 comments

Comments

@Manrich121
Copy link
Contributor

Setup

I am using usePowerSyncWatchedQuery and have the following watched query that performs a LEFT JOIN across three tables:

  • Two normal PowerSync Table tables -> lists and todos
  • One LocalOnly table -> attachments
const todos = usePowerSyncWatchedQuery<TodoEntry>(
    `SELECT
            todos.id AS todo_id,
            todos*,
            attachments.id AS attachment_id, 
            attachments.*
        FROM 
            todos
        LEFT JOIN 
            lists ON todos.list_id = lists.id
        LEFT JOIN 
            attachments ON todos.photo_id = attachments.id
        WHERE 
            todos.list_id = ?`,
    [listID],
    { tables: ['todos', 'lists', 'attachments'] }
);

Problem

Without specifying tables in the options payload, the query does not update when making changes to the LocalOnly table attachments.

Solution

As pointed out by @rkistner,

[It] should be fixed in the underlying lib. I assume it's just this bit that doesn't work for local-only tables:
https://github.com/journeyapps/powersync-react-native-sdk/blob/af0031b0eabb4524ad2a507b09487c68d268abb1/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts#L404

The solution is to instead use the already defined RegEx, here: https://github.com/journeyapps/powersync-react-native-sdk/blob/af0031b0eabb4524ad2a507b09487c68d268abb1/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts#L40

@Manrich121 Manrich121 changed the title Watched LEFT JOIN query does not update on localOnly table Watched LEFT JOIN query does not update on local-only table Oct 25, 2023
@stevensJourney
Copy link
Collaborator

This has been fixed in #7. Should be released in version 0.0.2 of the SDK packages.

@stevensJourney
Copy link
Collaborator

Version 0.0.2 of SDK packages have been published. Closing this issue.

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

No branches or pull requests

2 participants