tinyplex / tinybase

The reactive data store for local‑first apps.
https://tinybase.org
MIT License
3.23k stars 65 forks source link

PowerSync support #130

Closed bndkt closed 3 months ago

bndkt commented 5 months ago

One of the great things about TinyBase is it's versatility in terms of persisters, and I'd like to propose a new Persister for PowerSync, a Postgres<>SQLite sync layer.

I've done a POC for this and it's working great, so I'd like to create a PR to add a PowerSync persister but wanted to discuss this here first.

One open issue I have is that PowerSync works with views and views do not support ON CONFLICT. I got it working locally by replacing ON CONFLICT with INSERT OR REPLACE, which in the case of TinyBase seems to be working well because the whole record is written anyways. I'm curious to get your thoughts on this, do you see any problem with using INSERT OR REPLACE here? If not, it might be an option to introduce an optional flag for the sqlite-persister to use INSERT OR REPLACE instead of ON CONFLICT.

Curious what your thought are and happy to create a PR to let you look at the code I've written so far.

jamesgpearce commented 5 months ago

Awesome! I don't recall a strong reason to use one vs the other, so if they are semantically approximate, I guess it should work. We should drape it in test suites to be certain :)

Feel free to put up the PR and we can riff on it there. ❤️

bndkt commented 3 months ago

Shipped with 4.8 (https://github.com/tinyplex/tinybase/pull/133)