Skip to content

SupabaseConnector does not support insert or replace #196

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

Closed
fredpedersen opened this issue May 29, 2025 · 3 comments
Closed

SupabaseConnector does not support insert or replace #196

fredpedersen opened this issue May 29, 2025 · 3 comments

Comments

@fredpedersen
Copy link

Currently, the SupabaseConnector just uses insert, this will fail if there are constraints on the remote database.

A Powersync PUT is supposed to be insert or replace (SQLite doesnt have ON CONFLICT). For this we need to update the Table or Schema to be able to specific the unique constraints for each table. Then on uploadData we can do something like this but adding the data from the schema:

table.upsert(data) {
                            onConflict = "timestamp,user_id"
                            ignoreDuplicates = false
                        }

Is there a way already to do this that I'm missing?

@michaelbarnes
Copy link

michaelbarnes commented May 30, 2025

@fredpedersen The purpose of the uploadData function is allow for any custom API calls or functions that need to handle the data that needs to be uploaded to your source backend database. This means you can already change the defaults that handle the upserts we provide in the demo SupabaseConnector, according to your apps domain specific logic.

@simolus3
Copy link
Contributor

I think for Kotlin specifically it's a reasonable request since we also ship a ready connector as part of the SDK (on the other SDK it's used for demos only). But it's also tricky to generate the upserts on clients because the local view of the schema doesn't know anything about which primary/unique keys exist on the database.

@fredpedersen
Copy link
Author

My thoughts too @simolus3. The connector is part of the SDK rather than a demo, and should have the functionality that supabase already supports in their library. Additionally, it's messy to just override SupabaseConnector and add custom rules for indexes. Really, you also need to modify the Table and Index objects too. I have created a fork that adds the functionality needed

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

3 participants