SQLSync

SQLSync is a collaborative offline-first wrapper around SQLite designed to synchronize web application state between users, devices, and the edge. It allows for eventually consistent data synchronization, enabling real-time local-first collaboration and presence.

Example Use Cases

  • Web Applications: Applications with a structured file-oriented data model, such as Figma, can use SQLSync to enable real-time collaboration. Each file can be a SQLSync database, allowing multiple users to work together seamlessly.
  • Edge Computing: SQLSync can run on the edge with high tolerance for unreliable network conditions, ensuring data consistency and availability.
  • Optimistic Mutations: Enables optimistic reads and writes on SQLite read replicas, improving performance and user experience.

SQLSync Demo

The best way to get a feel for how SQLSync behaves is to play with the Todo list demo. Clicking the link will create a unique to-do list and redirect you to its unique URL. You can then share that URL with friends or open it on multiple devices (or browsers) to see the power of offline-first collaborative SQLite.

You can also learn more about SQLSync and its goals by watching Carl's WasmCon 2023 talk. Watch the recording here.

Features

  • Eventually Consistent SQLite: Ensures that all nodes eventually reach the same state.
  • Optimistic Reads and Writes: Improves user experience by making operations feel instant.
  • Reactive Query Subscriptions: Allows real-time updates based on data changes.
  • Real-time Collaboration: Supports multiple users editing the same data simultaneously.
  • Offline-first: Works seamlessly offline and syncs changes when back online.
  • Cross-tab Sync: Synchronizes data across multiple tabs in the same browser.
  • React Library: Provides a React library for easy integration.

Installation & Getting Started

To get started with SQLSync, refer to the guide to learn how to add SQLSync to your application.

Tips & Tricks

How to Debug SQLSync in the Browser

By default, SQLSync runs in a shared web worker, allowing the database to be shared between different tabs. This can make SQLSync a bit harder to debug. The easiest way to debug is to use Google Chrome and go to chrome://inspect/#workers. On that page, you'll find a list of all the running shared workers in other tabs. Assuming another tab is running SQLSync, you'll see the shared worker listed. Click inspect to open up dev-tools for the worker.

Missing Table or Multiple Statements Not Executing

SQLSync uses [rusqlite] under the hood to run and query SQLite. Unfortunately, the execute method only supports single statements and silently ignores trailing statements. If you are using execute!(...) in your reducer, make sure that each call only runs a single SQL statement.

For example:

// DON'T DO THIS:
execute!("create table foo (id int); create table bar (id int);").await?;
 
// DO THIS:
execute!("create table foo (id int)").await?;
execute!("create table bar (id int)").await?;

Similar Projects