electric-sql / electric

Sync little subsets of your Postgres data into local apps and services.
https://electric-sql.com
Apache License 2.0
6.41k stars 154 forks source link

How electric-next synchronize data into local database such as sqlite #1492

Closed ryzencool closed 2 months ago

ryzencool commented 3 months ago

I read the document, but now I confused how electric-next sync data into local database, http api get the data and then how to update data in the local database?

mianala commented 3 months ago

Same here — I’m using Expo/SQLite and Drizzle. From what I understand, some integration might be needed. For instance, Drizzle would likely require a feature or middleware to sync with Electric.

KyleAMathews commented 3 months ago

You use ShapeStreamhttps://next.electric-sql.com/api/clients/typescript#shapestream

It lets you subscribe to the stream of updates to the shape which you can then apply to the local db. Reading through the Redis example might help: https://github.com/electric-sql/electric/blob/main/examples/redis-client/src/index.ts

balegas commented 2 months ago

Here is how we did for PGlite. The code for SQLite should be quite similar. https://github.com/electric-sql/pglite/blob/main/packages/pglite-sync/src/index.ts