Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 0b9da95

Browse files
committed
Merge branch 'master' of github.com:phillmac/Orbit-db-API
2 parents c9a2d0c + 6e85cf7 commit 0b9da95

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

README.md

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,30 @@ curl http://localhost:3000/db/docstore
6565
{"address":{"root":"zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq","path":"docstore"},"dbname":"docstore","id":"/orbitdb/zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq/docstore","options":{"create":"true","indexBy":"_id","localOnly":false,"maxHistory":-1,"overwrite":true,"replicate":true},"type":"docstore"}
6666
```
6767

68+
### GET /db/:dbname/value
69+
70+
Gets the current value from counter database :dbname.
71+
72+
Returns the current counter value.
73+
74+
Can only be used on counter.
75+
76+
```shell
77+
curl -X GET http://localhost:3000/db/counter/value
78+
```
79+
80+
```json
81+
1
82+
```
83+
6884
### GET /db/:dbname/query
6985

7086
Queries the database :dbname.
7187

7288
Returns a list of found items as a JSON array.
7389

7490
```shell
75-
curl http://localhost:3001/db/docstore/query -X GET -H "Content-Type: application/json" --data '{"values":[]}'
91+
curl http://localhost:3000/db/docstore/query -X GET -H "Content-Type: application/json" --data '{"values":[]}'
7692
```
7793

7894
```json
@@ -90,21 +106,50 @@ curl http://localhost:3000/db/docstore/query -X GET -H "Content-Type: applicatio
90106
[{"project":"IPFS","site":"https://ipfs.io","likes":400}]
91107
```
92108

93-
Available operators are:
109+
Available operator short-codes are:
110+
111+
```eq``` propname equals value. Equivalent to "=="
112+
113+
```ne``` propname is not equals to value. Equivalent to "!="
94114

95-
==
115+
```gt``` propname is greater than value. Equivalent to ">"
96116

97-
\>
117+
```lt``` propname is less than value. Equivalent to "<"
98118

99-
<
119+
```gte``` propname is greater than or equal to value. Equivalent to ">="
120+
121+
```lte``` propname is less than or equal to value. Equivalent to "<="
122+
123+
```mod``` Perform a modulus calculation on propname using value. Equivalent to "%"
124+
125+
```range``` Perform a range query, comparing propname to min and max.
126+
127+
```all``` Fetch all records for field propname. Equivalent to "*"
128+
129+
#### Modulus Query
130+
131+
When using a modulus query, you must supply the divisor and the remainder. For example, to obtain all likes which are multiples of 100, you would specify a divisor 100 and a remainder 0:
132+
133+
```shell
134+
curl -X GET http://localhost:3000/db/docstore/query -H "Content-Type:application/json" --data '{"propname":"likes", "comp":"mod", "values":[100,0]}'
135+
```
136+
137+
```json
138+
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
139+
```
100140

101-
\>=
141+
#### Range Query
102142

103-
<=
143+
When specifying a range query, you must supply the min and max
144+
values. For example, to obtain all likes greater than 250 but less than 1000 the min and max must be supplied:
104145

105-
%
146+
```shell
147+
curl -X GET http://localhost:3000/db/docstore/query -H "Content-Type:application/json" --data '{"propname":"likes", "comp":"range", "values":[250,1000]}'
148+
```
106149

107-
\*
150+
```json
151+
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
152+
```
108153

109154
### GET /db/:dbname/:item
110155

@@ -153,7 +198,7 @@ Gets items from an eventlog or feed database :dbname.
153198

154199
Returns a list of matching objects as a JSON array.
155200

156-
Can be only used on eventlog|feed.
201+
Can only be used on eventlog|feed.
157202

158203
```shell
159204
curl -X GET http://localhost:3000/db/feed/iterator
@@ -182,7 +227,7 @@ Adds a new entry to the eventlog or feed database :dbname.
182227

183228
Returns the multihash of the new record entry.
184229

185-
Can be only used on eventlog|feed
230+
Can only be used on eventlog|feed
186231

187232
```shell
188233
curl -X POST http://localhost:3000/db/feed/add -d 'feed-item-1'
@@ -206,6 +251,34 @@ curl -X POST http://localhost:3000/db/docstore/put -H "Content-Type: application
206251
zdpuAkkFaimxyRE2bsiLRSiybkku3oDi4vFHqPZh29BABZtZU
207252
```
208253

254+
### POST|PUT /db/:dbname/inc
255+
256+
Increments the counter database :dbname by 1.
257+
258+
Returns a multihash of the new counter value.
259+
260+
```shell
261+
curl -X POST http://localhost:3000/db/counter/inc
262+
```
263+
264+
```json
265+
zdpuAmHw9Tcc4pyVjcVX3rJNJ7SGffmu4EwjodzmaPBVGGzbd
266+
```
267+
268+
### POST|PUT /db/:dbname/inc/:val
269+
270+
Increments the counter database :dbname by :val.
271+
272+
Returns a multihash of the new counter value.
273+
274+
```shell
275+
curl -X POST http://localhost:3000/db/counter/inc/100
276+
```
277+
278+
```json
279+
zdpuAmHw9Tcc4pyVjcVX3rJNJ7SGffmu4EwjodzmaPBVGGzbd
280+
```
281+
209282
### DELETE /db/:dbname/:item
210283

211284
Deletes the item specified by :item from the database :dbname.

src/lib/orbitdb-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class OrbitdbAPI extends Express {
102102
'gte': (a, b) => a >= b,
103103
'lte': (a, b) => a <= b,
104104
'mod': (a, b, c) => a % b == c,
105-
'range': (a, b, c) => min(b,c) <= a && a >= max(b,c),
105+
'range': (a, b, c) => Math.max(b,c) >= a && a >= Math.min(b,c),
106106
'all': () => true
107107
};
108108

0 commit comments

Comments
 (0)