levelup database adapter for Yjs
Use the levelup database adapter to store your shared data persistently in NodeJs applications. The changes will persist after restart.
For more info see:
This is a fork of y-leveldb, which uses leveldown to store data in the filesystem.
In order to support remote databases via levelup, a couple of changes have been made:
- Rather than creating a DB per room, use a single database for all rooms and implement rooms as sublevels.
- For optimal room startup, run the OS as an in-memory database whose operations are also streamed to the remote database.
- This was an experiment that has turned out to work pretty well.
- so YMMV.
- This is just source code adapted from its original app.
- I haven't worked out the YJS build system yet so there is no dist or NPM package.
- SS and DS are not run in-memory as OS is. It might be worth exploring.
var db = require('levelup')(process.env.MONGODB_URI || 'localhost/yjs-rooms', { db: require('mongodown') })
require('y-levelup')(Y, db)
Y({
db: {
name: 'levelup',
namespace: 'textarea-example' (optional - defaults to connector.room),
},
connector: {
name: 'websockets-client', // use the websockets connector
room: 'textarea-example'
},
share: {
textarea: 'Text' // y.share.textarea is of type Y.Text
}
}).then(function (y) {
// bind the textarea to a shared text element
y.share.textarea.bind(document.getElementById('textfield'))
}
Yjs is licensed under the MIT License.