Skip to content

Commit d552e99

Browse files
author
Ahmed Elghareeb
committed
fix: moves dbUtils.js inside src
This makes it easier to identify this script as part of the source code. Also, it's easier to make the src folder as a volume for docker compose for realtime update of the contents while the container is running.
1 parent e03dd72 commit d552e99

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

web/backend/dbUtils.js

-45
This file was deleted.

web/backend/src/dbUtils.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This file provides utility functions to handle an lmdb database. You can use
2+
// the node CLI to call those functions:
3+
//
4+
// node -e 'require("./dbUtils").addAdmin("./dvoting-users", 1234)'
5+
// node -e 'require("./dbUtils").listEls("./dvoting-users")'
6+
// node -e 'require("./dbUtils").removeEl("./dvoting-users", 1234)'
7+
//
8+
// If your are running this script outside of this module, specify NODE_PATH=
9+
10+
const lmdb = require('lmdb');
11+
12+
const addAdmin = (dbPath, sciper) => {
13+
const usersDB = lmdb.open({ path: dbPath });
14+
15+
usersDB
16+
.put(String(sciper), 'admin')
17+
.then(() => {
18+
console.log('ok');
19+
})
20+
.catch((error) => {
21+
console.log(error);
22+
});
23+
};
24+
25+
const listEls = (dbPath) => {
26+
const db = lmdb.open({ path: dbPath });
27+
28+
db.getRange({}).forEach(({ key, value }) => {
29+
console.log(`'${key}' => '${value}' \t | \t (${typeof key}) => (${typeof key})`);
30+
});
31+
};
32+
33+
const removeEl = (dbPath, key) => {
34+
const db = lmdb.open({ path: dbPath });
35+
36+
db.remove(String(key))
37+
.then(() => {
38+
console.log(`key '${key}' removed`);
39+
})
40+
.catch((error) => {
41+
console.log(`error: ${error}`);
42+
});
43+
};
44+
45+
module.exports = { addAdmin, listEls, removeEl };

web/backend/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"jest.config.js",
3636
".eslintrc",
3737
"dist",
38-
"dbUtils.js"
38+
"src/dbUtils.js"
3939
],
4040
"typedocOptions": {
4141
"entryPoints": [

0 commit comments

Comments
 (0)