Gathering detailed insights and metrics for p2p-db-osm
Gathering detailed insights and metrics for p2p-db-osm
Gathering detailed insights and metrics for p2p-db-osm
Gathering detailed insights and metrics for p2p-db-osm
npm install p2p-db-osm
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Pluggable API for p2p-db adding OpenStreetMap data types and querying.
1var P2P = require('p2p-db') 2var osm = require('p2p-db-osm') 3var hyperdb = require('hyperdb') 4var ram = require('random-access-memory') 5var memdb = require('memdb') 6var Geo = require('grid-point-store') 7 8// Create p2p-db and p2p-db-osm dependencies 9var hyperdb = P2P.provide('hyperdb', hyperdb(ram, { valueEncoding: 'json' })) 10var leveldb = P2P.provide('leveldb', memdb()) 11var pointstore = P2P.provide('pointstore', Geo(memdb())) 12 13// Create the p2p-db 14var db = P2P([hyperdb, leveldb, pointstore, osm]) 15 16var node = { 17 type: 'node', 18 lat: '-12.7', 19 lon: '1.3', 20 tags: { feature: 'water fountain' }, 21 changeset: 'abcdef' 22} 23 24db.osm.create(node, function (err, node) { 25 console.log('created node with id', node.id) 26 db.osm.get(node.id, function (err, elms) { 27 console.log('got elements at', node.id) 28 console.log(elms) 29 }) 30})
outputs
created node with id 78d06921416fe95b
got elements at 78d06921416fe95b
[ { type: 'node',
lat: '-12.7',
lon: '1.3',
tags: { feature: 'water fountain' },
changeset: 'abcdef',
timestamp: '2017-12-16T00:15:55.238Z',
id: '78d06921416fe95b',
version: 'eAXxidJuq9PoqiDsyrLKfR4jME9hgYnGSozS7BKXUqbDH' } ]
1var osm = require('p2p-db-osm')
Returns a depj dependency object, which is no more than
1module.exports = { 2 gives: 'osm', 3 needs: ['hyperdb', 'leveldb', 'pointstore'], 4 create: function (api) { 5 return new Osm(api) 6 } 7}
This is passed as a dependency directly into the p2p-db constructor. See p2p-db for more details on how this works.
You create a new p2p-db with p2p-db-osm like so:
1var P2P = require('p2p-db') 2 3var db = P2P([ 4 P2P.provide('hyperdb', hyperdb), 5 P2P.provide('leveldb', leveldb), 6 P2P.provide('pointstore', pointstore), 7 require('p2p-db-osm') 8])
Where hyperdb
is a hyperdb instance,
leveldb
is a levelup instance, and
pointstore
is a grid-point-store
instance. The order they are given doesn't matter --
depj sorts it out.
If you just want to use p2p-db-osm and don't care about p2p-db, that's fine too! You can get around the dependency management business and make a plain osmdb like so:
1var osm = require('p2p-db-osm') 2 3var osmdb = osm.create({ 4 hyperdb: hyperdb, 5 leveldb: leveldb, 6 pointstore: pointstore 7}) 8 9osmdb.create({type: 'node', ...}) // etc
Create the new OSM element element
and add it to the database. The resulting
element, populated with the id
and version
fields, is returned by the
callback cb
.
Fetch all of the newest OSM elements with the ID id
. In the case that multiple
peers modified an element prior to sync'ing with each other, there may be
multiple latest elements ("heads") for the ID.
Update an existing element with ID id
to be the OSM element element
. The new
element should have all fields that the OSM element would have. The type
of
the element cannot be changed.
If the value of ID currently returns two or more elements, this new value will replace them all.
cb
is called with the new element, including id
and version
properties.
Create and update many elements atomically. ops
is an array of objects
describing the elements to be added or updated.
1{ 2 type: 'put', 3 id: 'id', 4 value: { /* element */ } 5}
If no id
field is set, the element is created, otherwise it is updated with
the element value
.
Currently, doing a batch insert skips many validation checks in order to be as fast as possible.
TODO: accept opts.validate
or opts.strict
Retrieves all node
s, way
s, and relation
s touching the bounding box bbox
.
bbox
is expected to be of the format [[minLat, maxLat], [minLon, maxLon]]
.
Latitude runs between (-85, 85)
, and longitude between (-180, 180)
.
A callback parameter cb
is optional. If given, it will be called as
cb(err, elements)
. If not provided or set to null
, a Readable stream will be
returned that can be read from as elements are emitted. The distinction between
the two is that the callback will buffer all results before they are returned,
but the stream will emit results as they arrive, resulting in much less
buffering. This can make a large impact on memory use for queries on large
datasets.
The following algorithm is used to determine what OSM elements are returned:
Fetch a list of all OSM elements belonging to the changeset id
. cb
is called
with an array of objects of the form:
1{ 2 id: '...', 3 version: '...' 4}
TODO: optionally return a readable stream
To delete an element, OSM
specifies to
set the visible
property to false
. This can be done using the db.osm.put
API above.
TODO: talk about forking data & forking architecture
With npm installed, run
$ npm install p2p-db-osm
ISC
No vulnerabilities found.
No security vulnerabilities found.