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

Commit 0f0c53f

Browse files
author
haydenyoung
committed
Delete a database.
1 parent d549b6a commit 0f0c53f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ 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+
try {
49+
await db.drop()
50+
dbm.db_list_remove(req.params.dbname)
51+
return res.json('')
52+
} catch (err) {
53+
console.log(err)
54+
next(err)
55+
}
56+
}))
57+
4458
this.delete('/db/:dbname/:item', asyncMiddleware( async (req, res, next) => {
4559
let db, hash
4660
db = await dbm.get(req.params.dbname)

0 commit comments

Comments
 (0)