1
1
# orbit-db-docstore
2
2
3
+ [ ![ npm] ( https://img.shields.io/npm/v/orbit-db-docstore.svg )] ( https://www.npmjs.com/package/orbit-db-docstore )
4
+ [ ![ Gitter] ( https://img.shields.io/gitter/room/nwjs/nw.js.svg )] ( https://gitter.im/orbitdb/Lobby )
5
+
3
6
> Document Store for orbit-db
4
7
5
8
Database for storing indexed documents. Stores documents by ` _id ` field by default but you can also specify a custom field to index by.
6
9
7
10
* This is a core data store in [ orbit-db] ( https://github.com/haadcode/orbit-db ) *
8
11
12
+ ## Table of Contents
13
+
14
+ - [Install](#install)
15
+ - [Usage](#usage)
16
+ - [API](#api)
17
+ - [docstore(name, options)](#docstorename-options)
18
+ - [License](#license)
19
+
9
20
## Install
10
21
22
+ This project uses [ npm] ( https://npmjs.com ) and [ nodejs] ( https://nodejs.org )
23
+
11
24
```
12
25
npm install orbit-db-docstore
13
26
```
@@ -25,7 +38,7 @@ const docstore = orbitdb.docstore('db name')
25
38
docstore .put ({ _id: ' hello world' , doc: ' all the things' })
26
39
.then (() => docstore .put ({ _id: ' sup world' , doc: ' other things' }))
27
40
.then (() => docstore .get (' hello' ))
28
- .then ((value ) => console .log (value))
41
+ .then ((value ) => console .log (value))
29
42
// [{ _id: 'hello world', doc: 'all the things'}]
30
43
31
44
```
@@ -38,7 +51,7 @@ const docstore = orbitdb.docstore('db name', { indexBy: 'doc' })
38
51
docstore .put ({ _id: ' hello world' , doc: ' some things' })
39
52
.then (() => docstore .put ({ _id: ' hello universe' , doc: ' all the things' }))
40
53
.then (() => docstore .get (' all' ))
41
- .then ((value ) => console .log (value))
54
+ .then ((value ) => console .log (value))
42
55
// [{ _id: 'hello universe', doc: 'all the things'}]
43
56
44
57
```
@@ -52,7 +65,7 @@ docstore.put({ _id: 'hello world', doc: 'some things', views: 10 })
52
65
.then (() => docstore .put ({ _id: ' hello universe' , doc: ' all the things' , views: 100 }))
53
66
.then (() => docstore .put ({ _id: ' sup world' , doc: ' other things' , views: 5 }))
54
67
.then (() => docstore .query ((e )=> e .views > 5 ))
55
- .then ((value ) => console .log (value))
68
+ .then ((value ) => console .log (value))
56
69
// [{ _id: 'hello world', doc: 'some things', views: 10}, { _id: 'hello universe', doc: 'all the things', views: 100}]
57
70
```
58
71
@@ -62,7 +75,7 @@ docstore.put({ _id: 'hello world', doc: 'some things', views: 10 })
62
75
63
76
### docstore(name, options)
64
77
65
- Package:
78
+ Package:
66
79
[ orbit-db-docstore] ( https://github.com/shamb0t/orbit-db-docstore )
67
80
68
81
``` javascript
@@ -79,14 +92,14 @@ docstore.put({ _id: 'hello world', doc: 'some things', views: 10 })
79
92
``` javascript
80
93
db .put ({ _id: ' QmAwesomeIpfsHash' , name: ' shamb0t' , followers: 500 }).then ((hash ) => ... )
81
94
```
82
-
95
+
83
96
- ** get (key)**
84
97
` ` ` javascript
85
98
const profile = db.get('shamb0t')
86
99
.map((e) => e.payload.value)
87
100
// [{ _id: 'shamb0t', name: 'shamb0t', followers: 500 }]
88
101
` ` `
89
-
102
+
90
103
- ** query (mapper)**
91
104
` ` ` javascript
92
105
const all = db.query((doc) => doc.followers >= 500)
@@ -97,7 +110,7 @@ docstore.put({ _id: 'hello world', doc: 'some things', views: 10 })
97
110
` ` ` javascript
98
111
db.del('shamb0t').then((removed) => ...)
99
112
` ` `
100
-
113
+
101
114
- ** events**
102
115
103
116
` ` ` javascript
@@ -106,6 +119,12 @@ docstore.put({ _id: 'hello world', doc: 'some things', views: 10 })
106
119
107
120
See [events](https: // github.com/haadcode/orbit-db/blob/master/API.md#events) for full description.
108
121
122
+ ## Contributing
123
+
124
+ If you think this could be better, please [open an issue](https: // github.com/orbitdb/orbit-db-docstore/issues/new)!
125
+
126
+ Please note that all interactions in @orbitdb fall under our [Code of Conduct](CODE_OF_CONDUCT .md ).
127
+
109
128
## License
110
129
111
130
[MIT ](LICENSE ) ©️ 2015 - 2018 shamb0t, Haja Networks Oy
0 commit comments