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

Commit f20745c

Browse files
authored
Merge pull request #2 from phillmac/db-delete
Delete a database.
2 parents d549b6a + ff5b1b8 commit f20745c

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ curl -X POST http://localhost:3000/db/counter/inc/100
297297
zdpuAmHw9Tcc4pyVjcVX3rJNJ7SGffmu4EwjodzmaPBVGGzbd
298298
```
299299

300+
### DELETE /db/:dbname
301+
302+
Deletes the local database :dbname. This does not delete any data from peers.
303+
304+
```shell
305+
curl -X DELETE http://localhost:3000/db/docstore
306+
```
307+
300308
### DELETE /db/:dbname/:item
301309

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

src/lib/db-manager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class DBManager {
1616
}
1717
};
1818

19+
this.db_list_remove = (dbname) => {
20+
delete _dbs[dbname];
21+
}
22+
1923
this.db_list = () => {
2024
let db_info_list = {};
2125
for (var dbn in _dbs) {
@@ -50,4 +54,3 @@ class DBManager {
5054
}
5155

5256
module.exports = DBManager;
53-

src/lib/orbitdb-api.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ class OrbitdbAPI extends Express {
4141
}
4242
});
4343

44+
this.delete('/db/:dbname', asyncMiddleware( async (req, res, next) => {
45+
let db
46+
db = await dbm.get(req.params.dbname)
47+
48+
await db.drop()
49+
dbm.db_list_remove(req.params.dbname)
50+
return res.json('')
51+
}))
52+
4453
this.delete('/db/:dbname/:item', asyncMiddleware( async (req, res, next) => {
4554
let db, hash
4655
db = await dbm.get(req.params.dbname)

0 commit comments

Comments
 (0)