-
-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Would fix #2544
fix #2514
fix #2516
fix #2350
Is your feature request related to a problem? Please describe.
- PGLite was originally part of the electric-sql stack, but has since been separated out.
- It sounded awesome to load geoms in PostGIS in your browser, and do geospatial processing.
- However we have a few issues:
- Although the postgres engine is running in the browser, the data store is a shim on top of indexeddb (OPFS support is limited for now, and may be difficult due to Safari limitations).
- Support for the PostGIS extension isn't there yet & there is no clear timeline for when it may arrive (very difficult bundling dependencies). As a result we simply store javarosa geoms from ODK in the db anyway...
- It's a heavy WASM library, meaning users on poor connections have a bad experience to start up (caching helps, but only goes so far).
- It also requires quite a bit of resource to both run the postgres engine, but also store all of the data in the browser memory, causing some of the related linked issues above.
Perhaps we should consider it's usage, and have electric-sql sync to a different data store, eventually backed by IndexedDB too (planned), but not requiring additional heavy libraries.
Note that IndexedDB has an approx 1 GB storage limit imposed in Safari, which we will use as the lowest common denominator here. That should be ample anyway.
Describe the solution you'd like
We should probably keep PGLite for now, then consider a refactor in future to one of these options (if needed).
- We should consider refactoring out PGLite and instead using something mentioned below, for the sake of user experience.
- PGLite is still an awesome project, and definitely has it's use cases! I'll be sad to migrate away from an SQL based data store in the browser 😢
TanstackDB
Important
Note that TanstackDB does not currently support being backed by IndexedDB, nor a svelte adapter. So this option is tentative, based on progress there. By the time we look into this, it may all be there though - so keep an eye on it.
- Enter https://github.com/TanStack/db, a collaboration between the team at TanStack and Electric.
- Again, it's built on IndexedDB, but is a lightweight lib itself, solving most of our issues.
- It's also extremely performant and optimised.
RXDB
- A mature established tool that is great.
- It can be backed (for free) by Dexie IndexedDB: https://rxdb.info/rx-storage-dexie.html
- The database models will be made, then syncing into rxdb.
- Needs more exploration, but this could be good.
Describe alternatives you've considered
- Numerous alternatives, too many to count.
- Dexie is the canonical indexeddb wrapper, but tanstack has many advantages over it.
- We could consider an SQLite backed approach, but similar problems to above.
Additional context
- Note we currently pull in state from electric, then update store items in Svelte. This is very inefficient. TanstackDB would optimise this, providing reactive local collections and mutations.