Skip to content

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

@Manrich121

Description

@Manrich121

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions