You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
y-op-sqlite is a persistence provider for Yjs that uses op-sqlite to store document changes in a SQLite database. This is useful for React Native projects that need to access YJS documents without an internet connection to enable a local-first experience.
Installing
You can install y-op-sqlite and its peer dependencies using expo:
# install using expo
npx expo install y-op-sqlite yjs @op-engineering/op-sqlite
Or alternatively using npm:
# install using npm
npm i y-op-sqlite yjs @op-engineering/op-sqlite
Make sure to check the op-sqlite docs for instructions on setting up op-sqlite in your React Native project.
Usage
import{OPSQLitePersistence}from'y-op-sqlite';// other code...constprovider=newOPSQLitePersistence(docName,ydoc);provider.whenSynced.then(()=>{console.log("content finished loading from database.");});
When you're done accessing the document, you can destroy the connection to the provider:
// stop syncing with databaseprovider.destroy();
Attribution
This library is based on y-indexdb by Kevin Jahns.
Thanks to @ospfranco for creating op-sqlite.