项目作者: keymetrics

项目描述 :
:construction_worker: Local and shared database
高级语言: JavaScript
项目地址: git://github.com/keymetrics/interdb.git
创建时间: 2018-01-17T16:07:54Z
项目社区:https://github.com/keymetrics/interdb

开源协议:

下载


InterDB

InterDB is a shared database with auto discovery.

Example

  1. const interdb = require('interdb')
  2. const con = new interdb()
  3. // Global
  4. con.startLocal('./path.local.db') // Start local db only
  5. con.start({
  6. namespace: 'business',
  7. password: 'long-password',
  8. path: './path.db',
  9. localPath: './path.local.db', // optional
  10. identity : {
  11. // Info that will be shared to other dashboards
  12. }
  13. }) // join network
  14. con.stop() // exit network
  15. // Bus
  16. con.clients.*
  17. // Refer to Synapsis documentation (https://github.com/Unitech/synapsis)
  18. // local DB
  19. con.localDb.put('key', 'value', cb) // put new data in existing key or create it
  20. con.localDb.push('key', 'value', cb) // push data in existing key if it's an array or create an array with value in first index
  21. con.localDb.del('key', cb) // delete key
  22. con.localDb.get('key') // get value from key
  23. con.localDb.updateAll({ data: {} }, cb) // Overwrite database
  24. con.localDb.getLastUpdate() // Get timestamp of latest action
  25. con.localDb.save(cb) // save changes (use if you modify con.localDb without API)
  26. // Shared DB (all of local API but broadcast changes over network)
  27. con.db.put('key', 'value', cb) // put new data in existing key or create it
  28. con.db.push('key', 'value', cb) // push data in existing key if it's an array or create an array with value in first index
  29. con.db.del('key', cb) // delete key
  30. con.db.get('key') // get value from key
  31. con.db.updateAll({ data: {} }, cb) // Overwrite database
  32. con.db.getLastUpdate() // Get timestamp of latest action
  33. con.db.save(cb) // save changes (use if you modify con.db without API)

Database structure

  1. {
  2. lastUpdate: "",
  3. data: {}
  4. }

Communication structure

Normal

Host A <-> Host B <-> Host C
^———————————^

Problem

Host A <-> Host B <-> Host C