passing-notes-rxdb
v1.0.0
Published
An HTTP replication middleware for RxDB that persists to SQLite
Downloads
195
Readme
passing-notes-rxdb
An HTTP replication middleware for RxDB that persists to SQLite, for use with passing-notes.
Usage
Install by running:
yarn add passing-notes-rxdb better-sqlite3Then compose it with other middleware:
import {compose} from 'passing-notes'
import {serveRxdb} from 'passing-notes-rxdb'
import {Persistence} from 'passing-notes-rxdb/sqlite'
const schemas = {
heroes: {
schema: {
version: 0,
primaryKey: 'id',
type: 'object',
properties: {
id: {type: 'string', maxLength: 36},
updatedAt: {type: 'integer'},
name: {type: 'string'},
},
},
},
}
const persistence = new Persistence(':memory:', schemas)
export default compose(
serveRxdb({persistence, path: '/data'}),
() => () => ({status: 404}),
)On the client:
import {createRxDatabase} from 'rxdb'
import {getRxStorageMemory} from 'rxdb/plugins/storage-memory'
import {replicateCollection} from 'passing-notes-rxdb/client'
const db = await createRxDatabase({
name: 'heroes',
storage: getRxStorageMemory(),
})
await db.addCollections({
heroes: {
schema: {
version: 0,
primaryKey: 'id',
type: 'object',
properties: {
id: {type: 'string', maxLength: 36},
updatedAt: {type: 'integer'},
name: {type: 'string'},
},
},
},
})
const replicationState = replicateCollection({
collection: db.heroes,
replicationIdentifier: 'heroes',
url: 'http://localhost:8080/data',
EventSource,
})
await replicationState.awaitInitialReplication()