UNPKG

y-cap-sqlite

Version:

y-cap-sqlite is a persistence provider for [Yjs](https://github.com/yjs/yjs) that uses [@capacitor-community/sqlite](https://github.com/capacitor-community/sqlite) to store document changes in a SQLite database. This is useful for Capacitor projects that

46 lines (28 loc) 1.33 kB
## About y-cap-sqlite is a persistence provider for [Yjs](https://github.com/yjs/yjs) that uses [@capacitor-community/sqlite](https://github.com/capacitor-community/sqlite) to store document changes in a SQLite database. This is useful for Capacitor projects that need to access YJS documents without an internet connection to enable a local-first experience. ## Installing You can install y-cap-sqlite and its peer dependencies using your favorite package manager: ```sh # install using npm npm install ls yjs @capacitor-community/sqlite # install using bun bun add y-cap-sqlite yjs @capacitor-community/sqlite # install using pnpm pnpm add y-cap-sqlite yjs @capacitor-community/sqlite ``` ## Usage ```ts import { CapSQLitePersistence } from 'y-cap-sqlite'; // other code... const provider = await OPSQLitePersistence.create(config: Omit<capConnectionOptions, "database">, doc: Y.Doc, name: string, sqlite: SQLiteConnection); 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: ```ts // stop syncing with database provider.destroy(); ``` ## Attribution This library is based on [y-op-sqlite](https://github.com/malte-j/y-op-sqlite) by Malte J, thanks to him for the support !