This repository was archived by the owner on Nov 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,22 @@ curl -X GET http://localhost:3000/db/feed/iterator -d 'limit=-1'
239239See [ OrbitDB's Iterator API] ( https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions-1 )
240240for more information.
241241
242+ ### GET /db/: dbname /all
243+
244+ Gets all items from a keyvalue database : dbname .
245+
246+ Returns all items from a keyvalue store as a JSON object.
247+
248+ Can only be used on keyvalue.
249+
250+ ``` shell
251+ curl -X GET http://localhost:3000/db/all
252+ ```
253+
254+ ``` json
255+ {"Key1" :{"name" :" Value1" },"Key2" :{"name" :" Value2" },"projects" :" {[" orbitdb","ipfs"] }}
256+ ```
257+
242258### POST|PUT /db/: dbname /add
243259
244260Adds a new entry to the eventlog or feed database : dbname .
@@ -269,6 +285,13 @@ curl -X POST http://localhost:3000/db/docstore/put -H "Content-Type: application
269285zdpuAkkFaimxyRE2bsiLRSiybkku3oDi4vFHqPZh29BABZtZU
270286```
271287
288+ For the keyvalue store, a JSON object containing the variables ` key ` and
289+ ` value ` must be passed in the POST data:
290+
291+ ``` shell
292+ curl -X POST http://localhost:3000/db/keyvalue/put -H " Content-Type: application/json" -d ' {"key":"Key","value":{ "name": "Value" }}'
293+ ```
294+
272295### POST|PUT /db/: dbname /inc
273296
274297Increments the counter database : dbname by 1.
Original file line number Diff line number Diff line change @@ -66,7 +66,14 @@ class OrbitdbAPI extends Express {
6666 var db_put = asyncMiddleware ( async ( req , res , next ) => {
6767 let db , hash
6868 db = await dbm . get ( req . params . dbname )
69- hash = await db . put ( req . body )
69+
70+ if ( db . type == 'keyvalue' ) {
71+ let params = req . body ;
72+ hash = await db . put ( params . key , params . value )
73+ } else {
74+ hash = await db . put ( req . body )
75+ }
76+
7077 return res . json ( hash )
7178 } ) ;
7279
@@ -153,6 +160,12 @@ class OrbitdbAPI extends Express {
153160 return res . json ( contents )
154161 } ) ) ;
155162
163+ this . get ( '/db/:dbname/all' , asyncMiddleware ( async ( req , res , next ) => {
164+ let db
165+ db = await dbm . get ( req . params . dbname )
166+ return res . json ( db . all ( ) )
167+ } ) ) ;
168+
156169 this . get ( '/db/:dbname/value' , asyncMiddleware ( async ( req , res , next ) => {
157170 let db , val
158171 db = await dbm . get ( req . params . dbname )
You can’t perform that action at this time.
0 commit comments