Skip to content

JamesKyburz/level-airplanedb

Repository files navigation

level-airplanedb

This module allows you to work offline in the browser using indexdb (+ shim for websql when indexdb not available).

You get a sync method in browserified client to write to the server. The server gets a sync method that returns a readstream of the changelog after the given timestamp.

js-standard-style build status npm downloads Sauce Test Status

Example client

const levelup = require('levelup')
const leveljs = require('level-js')
const airplanedb = require('level-airplanedb')

const db = airplanedb(levelup('test', {db: leveljs}))

// sync range
// any keys in local changelog will be written to the server
// any keys from remotedb will be synced to client
db.sync({start: ..., end: ...}, remotedb, cb)

// changes to local db will be written to changelog removed when synced.

Example server

const levelup = require('levelup')
const leveldown = require('leveldown')
const airplanedb = require('level-airplanedb')

const db = airplanedb(levelup('test', {db: leveldown}))

db.sync(from, range) // readstream of changelog >= from

Background

In the spirit of offline first I wanted a working offline storage, giving me the choice when to sync saving battery usage.

level-sublevel is used to persist the changelog both on client and server.

See test/simple.js for a client server example using :-

multilevel - leveldb over network

level-js - leveldown api in the browser

Gotchas

This is a work in progress, conflicts are not handled at all! The client's changelog is what is written to the server.

Updating keys in the same range as a running sync is not supported, doing this will incur loss of data.

install

With npm do:

npm install level-airplanedb

test

npm test

license

MIT

About

offline leveldb library with sync feature

Resources

License

Stars

Watchers

Forks

Packages

No packages published