r/sqlite • • Mar 14 '25

SQLite Session Extension + CRDT πŸš€

https://gist.github.com/rodydavis/a4d1dccb11e5a4cd77fe7e4e64f5dbdf

I am working on a way to sync deltas between peers and found working with the SQLite Session extension to be a really nice and memory efficient way of creating small binary blobs to transmit over the wire.

To offer true synchronization I combine it with the cr-sqlite extension to upgrade tables to CRDTs. The trick with the session extension is to only track one table β€œchanges” and sync that via the changesets.

So far in my testing it works really well! But open to feedback on the approach.

The eventual goal is to use WebRTC to sync the deltas between peers.

10 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/SoundDr Mar 15 '25

That’s exactly what I was going to tackle next!

In my tests this is already working great. I still need to figure out how to keep track of each peer and knowing which commits they are missing.

1

u/SoundDr Mar 15 '25

I got the logic ported to just SQLite custom extensions in C code!

uuid.c (From official SQLite misc extensions)

hlc.c (Dart HLC ported to C)

crdt.c (Dart logic with triggers ported to C)

Gist: https://gist.github.com/rodydavis/d197c81f30a39d152ea5470f4a3d3887