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

Commit 5fa2af9

Browse files
author
haydenyoung
committed
/inc and range/mod /query.
1 parent cb952ea commit 5fa2af9

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

README.md

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Queries the database :dbname.
8888
Returns a list of found items as a JSON array.
8989

9090
```shell
91-
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":[]}'
9292
```
9393

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

109-
Available operators short-codes are:
109+
Available operator short-codes are:
110110

111-
```eq``` propname equals value. Equivalent to "=="
111+
```eq``` propname equals value. Equivalent to "=="
112112

113-
```gt``` propname is greater than value. Equivalent to ">"
113+
```ne``` propname is not equals to value. Equivalent to "!="
114114

115-
```lt``` propname is less than value. Equivalent to "<"
115+
```gt``` propname is greater than value. Equivalent to ">"
116116

117-
```gte``` propname is greater than or equal to value. Equivalent to ">="
117+
```lt``` propname is less than value. Equivalent to "<"
118118

119-
```lte``` propname is less than or equal to value. Equivalent to "<="
119+
```gte``` propname is greater than or equal to value. Equivalent to ">="
120120

121-
```mod``` Perform a modulus calculation on propname using value. Equivalent to "%"
121+
```lte``` propname is less than or equal to value. Equivalent to "<="
122122

123-
```all``` Fetch all records for field propname. Equivalent to "*"
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+
```
140+
141+
#### Range Query
142+
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:
145+
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+
```
149+
150+
```json
151+
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
152+
```
124153

125154
### GET /db/:dbname/:item
126155

@@ -222,6 +251,34 @@ curl -X POST http://localhost:3000/db/docstore/put -H "Content-Type: application
222251
zdpuAkkFaimxyRE2bsiLRSiybkku3oDi4vFHqPZh29BABZtZU
223252
```
224253

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+
225282
### DELETE /db/:dbname/:item
226283

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

0 commit comments

Comments
 (0)