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

Commit ca40e04

Browse files
authored
Merge pull request #17 from orbitdb/fix/POST_query
POST json params to query endpoint.
2 parents 395082d + 5fefbfa commit ca40e04

File tree

3 files changed

+78
-75
lines changed

3 files changed

+78
-75
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ typings/
6363
# ignore certificates
6464
*.crt
6565
*.key
66+
67+
# ignore local db repository
68+
orbitdb/

Diff for: README.md

+74-74
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
- [GET /dbs](#get-dbs)
1515
- [GET /db/:dbname](#get-dbdbname)
1616
- [GET /db/:dbname/value](#get-dbdbnamevalue)
17-
- [GET /db/:dbname/query](#get-dbdbnamequery)
18-
- [Modulus Query](#modulus-query)
19-
- [Range Query](#range-query)
2017
- [GET /db/:dbname/:item](#get-dbdbnameitem)
2118
- [GET /db/:dbname/iterator](#get-dbdbnameiterator)
2219
- [GET /db/:dbname/index](#get-dbdbnameindex)
2320
- [GET /identity](#get-identity)
2421
- [POST /db/:dbname](#post-dbdbname)
22+
- [POST /db/:dbname/query](#post-dbdbnamequery)
23+
- [Modulus Query](#modulus-query)
24+
- [Range Query](#range-query)
2525
- [POST|PUT /db/:dbname/add](#post-put-dbdbnameadd)
2626
- [POST|PUT /db/:dbname/put](#post-put-dbdbnameput)
2727
- [POST|PUT /db/:dbname/inc](#post-put-dbdbnameinc)
2828
- [POST|PUT /db/:dbname/inc/:val](#post-put-dbdbnameincval)
29-
- [POST|PUT /db/:dbname/access/write](#post-put-dbdbnameaccesswrite)
29+
- [POST|PUT /db/:dbname/access/writ](#post-put-dbdbnameaccesswrite)
3030
- [DELETE /db/:dbname](#delete-dbdbname)
3131
- [DELETE /db/:dbname/:item](#delete-dbdbnameitem)
3232
- [Contribute](#contribute)
@@ -122,76 +122,6 @@ curl -X GET http://localhost:3000/db/counter/value
122122
1
123123
```
124124

125-
### GET /db/:dbname/query
126-
127-
Queries the database :dbname.
128-
129-
Returns a list of found items as a JSON array.
130-
131-
```shell
132-
curl http://localhost:3000/db/docstore/query -X GET -H "Content-Type: application/json" --data '{"values":[]}'
133-
```
134-
135-
```json
136-
[{"project":"OrbitDB","site":"https://github.com/orbitdb/orbit-db","likes":200},{"project":"IPFS","site":"https://ipfs.io","likes":400}]
137-
```
138-
139-
To query a subset of data, a condition can be specified. For example, to
140-
retrieve only those entries which have a total number of likes above 300:
141-
142-
```shell
143-
curl http://localhost:3000/db/docstore/query -X GET -H "Content-Type: application/json" --data '{"propname":"likes","comp":">","values":[300]}'
144-
```
145-
146-
```json
147-
[{"project":"IPFS","site":"https://ipfs.io","likes":400}]
148-
```
149-
150-
Available operator short-codes are:
151-
152-
```eq``` propname equals value. Equivalent to "=="
153-
154-
```ne``` propname is not equals to value. Equivalent to "!="
155-
156-
```gt``` propname is greater than value. Equivalent to ">"
157-
158-
```lt``` propname is less than value. Equivalent to "<"
159-
160-
```gte``` propname is greater than or equal to value. Equivalent to ">="
161-
162-
```lte``` propname is less than or equal to value. Equivalent to "<="
163-
164-
```mod``` Perform a modulus calculation on propname using value. Equivalent to "%"
165-
166-
```range``` Perform a range query, comparing propname to min and max.
167-
168-
```all``` Fetch all records for field propname. Equivalent to "*"
169-
170-
#### Modulus Query
171-
172-
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:
173-
174-
```shell
175-
curl -X GET http://localhost:3000/db/docstore/query -H "Content-Type:application/json" --data '{"propname":"likes", "comp":"mod", "values":[100,0]}'
176-
```
177-
178-
```json
179-
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
180-
```
181-
182-
#### Range Query
183-
184-
When specifying a range query, you must supply the min and max
185-
values. For example, to obtain all likes greater than 250 but less than 1000 the min and max must be supplied:
186-
187-
```shell
188-
curl -X GET http://localhost:3000/db/docstore/query -H "Content-Type:application/json" --data '{"propname":"likes", "comp":"range", "values":[250,1000]}'
189-
```
190-
191-
```json
192-
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
193-
```
194-
195125
### GET /db/:dbname/:item
196126

197127
Gets a record identified by :item from the database :dbname.
@@ -336,6 +266,76 @@ overwrite flag:
336266
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore" -d "overwrite=true"
337267
```
338268

269+
### POST /db/:dbname/query
270+
271+
Queries the database :dbname.
272+
273+
Returns a list of found items as a JSON array.
274+
275+
```shell
276+
curl http://localhost:3000/db/docstore/query -X GET -H "Content-Type: application/json" --data '{"values":[]}'
277+
```
278+
279+
```json
280+
[{"project":"OrbitDB","site":"https://github.com/orbitdb/orbit-db","likes":200},{"project":"IPFS","site":"https://ipfs.io","likes":400}]
281+
```
282+
283+
To query a subset of data, a condition can be specified. For example, to
284+
retrieve only those entries which have a total number of likes above 300:
285+
286+
```shell
287+
curl http://localhost:3000/db/docstore/query -X GET -H "Content-Type: application/json" --data '{"propname":"likes","comp":">","values":[300]}'
288+
```
289+
290+
```json
291+
[{"project":"IPFS","site":"https://ipfs.io","likes":400}]
292+
```
293+
294+
Available operator short-codes are:
295+
296+
```eq``` propname equals value. Equivalent to "=="
297+
298+
```ne``` propname is not equals to value. Equivalent to "!="
299+
300+
```gt``` propname is greater than value. Equivalent to ">"
301+
302+
```lt``` propname is less than value. Equivalent to "<"
303+
304+
```gte``` propname is greater than or equal to value. Equivalent to ">="
305+
306+
```lte``` propname is less than or equal to value. Equivalent to "<="
307+
308+
```mod``` Perform a modulus calculation on propname using value. Equivalent to "%"
309+
310+
```range``` Perform a range query, comparing propname to min and max.
311+
312+
```all``` Fetch all records for field propname. Equivalent to "*"
313+
314+
#### Modulus Query
315+
316+
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:
317+
318+
```shell
319+
curl -X POST http://localhost:3000/db/docstore/query -H "Content-Type:application/json" --data '{"propname":"likes", "comp":"mod", "values":[100,0]}'
320+
```
321+
322+
```json
323+
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
324+
```
325+
326+
#### Range Query
327+
328+
When specifying a range query, you must supply the min and max
329+
values. For example, to obtain all likes greater than 250 but less than 1000 the min and max must be supplied:
330+
331+
```shell
332+
curl -X GET http://localhost:3000/db/docstore/query -H "Content-Type:application/json" --data '{"propname":"likes", "comp":"range", "values":[250,1000]}'
333+
```
334+
335+
```json
336+
[{"site":"https://ipfs.io","likes":400,"project":"IPFS"},{"site":"https://github.com/orbitdb/orbit-db","likes":200,"project":"OrbitDB"}]
337+
```
338+
339339
### POST|PUT /db/:dbname/add
340340

341341
Adds a new entry to the eventlog or feed database :dbname.

Diff for: src/lib/orbitdb-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class OrbitdbAPI {
188188
})
189189
},
190190
{
191-
method: 'GET',
191+
method: 'POST',
192192
path: '/db/{dbname}/query',
193193
handler: dbMiddleware( async (db, request, _h) => {
194194
let qparams, comparison, query;

0 commit comments

Comments
 (0)