Skip to content

Private peer-to-peer collaborative databases in the browser using SQLite (WebAssembly) and WebRTC.

Notifications You must be signed in to change notification settings

adhamsalama/sqlite-wasm-webrtc

Repository files navigation

Peer-to-peer collaborative database editing & sharing in the browser. No server required.

This project uses SQLite compiled to WebAssembly in the browser as the database, and provides collaborative funcionalities using WebRTC.

Evey peer has their own SQLite DB in their browser, and SQL statements are sent to peers using WebRTC, providing a private and secure way to share and manipulate data.

Install

npm i

Build

npm run build

Run

node server.js
  • Open a browser browser instance at http://localhost:8080/index.html.
  • Click "Create Room" and enter a room name.
  • Open another browser instance at the same URL.
  • Click "Join Room" and enter the same room name.

Now you and your peers are connected using WebRTC. Every query or file you import will be replicated to your peers.

This has the benefit of being private and secure because the database and the queries run on it are shared between you and you peers only.

I initially used PGLite which has excellent documentation and is very easy to use, but found it too heavy for this use case. SQLite is lighter and more suitable to running a database in the browser.

The docs for running SQLite in a web worker with persistance weren't easy, and I eventually had to add a bit of code to SQLite's WASM glue to make it easier to use.

I copied my existing WebRTC app project and removed unnecessary parts (video/audio/screen sharing), and kept DataChannels. So for more resources about WebRTC you can check my WebRTC repo.

Resources

About

Private peer-to-peer collaborative databases in the browser using SQLite (WebAssembly) and WebRTC.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published