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.
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.
import { OPSQLitePersistence } from 'y-op-sqlite';
// other code...
const provider = new OPSQLitePersistence(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 database
provider.destroy();
This library is based on y-indexdb by Kevin Jahns. Thanks to @ospfranco for creating op-sqlite.