digidem / osm-p2p-db

Peer-to-peer database for OpenStreetMap data
BSD 2-Clause "Simplified" License
237 stars 25 forks source link

listing conflicts (forks) #4

Closed gmaclennan closed 8 years ago

gmaclennan commented 8 years ago

Can we add an example for listing forked records? Should we add a method osm.conflicts() for this?

ghost commented 8 years ago

This would be good to have as a method, or at least an example.

ghost commented 8 years ago

I added an example in test/fork_count.js:

var hyperlog = require('hyperlog')
var fdstore = require('fd-chunk-store')

var level = require('level')
var db = level('/tmp/whatever.db')
var logdb = level('/tmp/whatever.log')

var osmdb = require('../')
var osm = osmdb({
  log: hyperlog(logdb, { valueEncoding: 'json' }),
  db: db,
  store: fdstore(4096, '/tmp/whatever.store')
})

osm.kv.createReadStream({ values: false })
  .on('data', function (row) {
    console.log(row.key, row.links.length)
  })

hyperkv has a createReadStream() method to list all the active keys, and row.links contains an array of all the forks of that key. When row.links.length > 1, there exists more than one version of a document. I've also added this use-case to the test suite and documented osm.kv.