mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-07 06:36:38 +00:00
commit
f9e8d57a9e
@ -18,7 +18,8 @@
|
|||||||
"orbit-db-eventstore": "0.1.5",
|
"orbit-db-eventstore": "0.1.5",
|
||||||
"orbit-db-feedstore": "0.1.4",
|
"orbit-db-feedstore": "0.1.4",
|
||||||
"orbit-db-kvstore": "0.1.3",
|
"orbit-db-kvstore": "0.1.3",
|
||||||
"orbit-db-pubsub": "0.0.4"
|
"orbit-db-pubsub": "0.0.4",
|
||||||
|
"orbit-db-docstore": "0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"asyncawait": "^1.0.6",
|
"asyncawait": "^1.0.6",
|
||||||
|
@ -5,6 +5,7 @@ const EventStore = require('orbit-db-eventstore')
|
|||||||
const FeedStore = require('orbit-db-feedstore')
|
const FeedStore = require('orbit-db-feedstore')
|
||||||
const KeyValueStore = require('orbit-db-kvstore')
|
const KeyValueStore = require('orbit-db-kvstore')
|
||||||
const CounterStore = require('orbit-db-counterstore')
|
const CounterStore = require('orbit-db-counterstore')
|
||||||
|
const DocumentStore = require('orbit-db-docstore')
|
||||||
const Pubsub = require('orbit-db-pubsub')
|
const Pubsub = require('orbit-db-pubsub')
|
||||||
const Cache = require('./Cache')
|
const Cache = require('./Cache')
|
||||||
|
|
||||||
@ -37,6 +38,10 @@ class OrbitDB {
|
|||||||
return this._createStore(CounterStore, dbname, options)
|
return this._createStore(CounterStore, dbname, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docstore(dbname, options) {
|
||||||
|
return this._createStore(DocumentStore, dbname, options)
|
||||||
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
if (this._pubsub) this._pubsub.disconnect()
|
if (this._pubsub) this._pubsub.disconnect()
|
||||||
this.events.removeAllListeners('data')
|
this.events.removeAllListeners('data')
|
||||||
|
@ -523,8 +523,92 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
const value = db.get('key1')
|
const value = db.get('key1')
|
||||||
assert.equal(value, 'hello2')
|
assert.equal(value, 'hello2')
|
||||||
}))
|
}))
|
||||||
await(db.put('key1', 'hello1'))
|
}))
|
||||||
await(db2.put('key1', 'hello2'))
|
})
|
||||||
|
|
||||||
|
describe('Document Store - default index \'_id\'', function() {
|
||||||
|
beforeEach(() => {
|
||||||
|
db = client.docstore(channel, { subscribe: false })
|
||||||
|
db.delete()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
db.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('put', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'all the things'}))
|
||||||
|
const value = db.get('hello world')
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello world', doc: 'all the things'}])
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('get - partial term match', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'some things'}))
|
||||||
|
await(db.put({ _id: 'hello universe', doc: 'all the things'}))
|
||||||
|
await(db.put({ _id: 'sup world', doc: 'other things'}))
|
||||||
|
const value = db.get('hello')
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello world', doc: 'some things' },
|
||||||
|
{ _id: 'hello universe', doc: 'all the things'}])
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('get after delete', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'some things'}))
|
||||||
|
await(db.put({ _id: 'hello universe', doc: 'all the things'}))
|
||||||
|
await(db.put({ _id: 'sup world', doc: 'other things'}))
|
||||||
|
await(db.del('hello universe'))
|
||||||
|
const value = db.get('hello')
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello world', doc: 'some things'}])
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('put updates a value', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'all the things'}))
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'some of the things'}))
|
||||||
|
const value = db.get('hello')
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello world', doc: 'some of the things'}])
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('query', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'all the things', views: 17}))
|
||||||
|
await(db.put({ _id: 'sup world', doc: 'some of the things', views: 10}))
|
||||||
|
await(db.put({ _id: 'hello other world', doc: 'none of the things', views: 5}))
|
||||||
|
await(db.put({ _id: 'hey universe', doc: ''}))
|
||||||
|
const value = db.query((e) => e.views > 5)
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello world', doc: 'all the things', views: 17},
|
||||||
|
{ _id: 'sup world', doc: 'some of the things', views: 10}])
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('query after delete', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'all the things', views: 17}))
|
||||||
|
await(db.put({ _id: 'sup world', doc: 'some of the things', views: 10}))
|
||||||
|
await(db.put({ _id: 'hello other world', doc: 'none of the things', views: 5}))
|
||||||
|
await(db.del('hello world'))
|
||||||
|
await(db.put({ _id: 'hey universe', doc: ''}))
|
||||||
|
const value = db.query((e) => e.views > 5)
|
||||||
|
assert.deepEqual(value, [{ _id: 'sup world', doc: 'some of the things', views: 10}])
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Document Store - specified index', function() {
|
||||||
|
beforeEach(() => {
|
||||||
|
db = client.docstore(channel, { subscribe: false, indexBy: 'doc' })
|
||||||
|
db.delete()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
db.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('put', async(() => {
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'all the things'}))
|
||||||
|
const value = db.get('all')
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello world', doc: 'all the things'}])
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('get - matches specified index', async(() => {
|
||||||
|
await(db.put({ _id: 'hello universe', doc: 'all the things'}))
|
||||||
|
await(db.put({ _id: 'hello world', doc: 'some things'}))
|
||||||
|
const value = db.get('all')
|
||||||
|
assert.deepEqual(value, [{ _id: 'hello universe', doc: 'all the things'}])
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user