@hocuspocus/extension-database
v4.0.0
Published
a generic Hocuspocus persistence driver for the database
Readme
@hocuspocus/extension-database
A generic persistence base class for Hocuspocus. Provide your own fetch and store functions to plug any database into the collaboration backend — Postgres, MySQL, MongoDB, a REST API, etc.
Installation
npm install @hocuspocus/extension-databaseUsage
Plug in any storage backend by implementing two async functions:
import { Server } from "@hocuspocus/server"
import { Database } from "@hocuspocus/extension-database"
const server = new Server({
extensions: [
new Database({
fetch: async ({ documentName }) => {
// return a Uint8Array of the stored Y.js update, or null for new documents
return await yourDb.findDocument(documentName)
},
store: async ({ documentName, state }) => {
// persist the binary Y.js state wherever you like
await yourDb.upsertDocument(documentName, state)
},
}),
],
})
server.listen()state is a Buffer containing the encoded Y.js update. Store it as-is and return it unchanged from fetch.
For dedicated storage drivers, see @hocuspocus/extension-sqlite or @hocuspocus/extension-s3, both of which extend this base class.
Documentation
Persistence patterns and performance tips: tiptap.dev/docs/hocuspocus/guides/persistence.
License
MIT — see LICENSE.md.
