-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.js
37 lines (32 loc) · 853 Bytes
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const config = require('./config/default.json');
const levelup = require('levelup');
const Commands = {
db: levelup(config.database, {valueEncoding: 'json'}),
db_get_all: function(prefix = '') {
this.db.createReadStream({
start: `${prefix}\x00`,
end: `${prefix}\xFF`
})
.on('data', console.log)
.on('error', console.log);
},
db_get: function(key) {
this.db.get(key, function (err, value) {
if (err) return console.log(err);
return console.log(value);
});
},
db_del: function(key) {
this.db.del(key, function (err) {
if (err) return console.log(err);
return console.log(`Removed ${key}`);
});
}
};
var command = process.argv[2];
var arg = process.argv[3];
console.log(`# Execute command with argument
command : ${command}
argument : ${arg}
`);
Commands[command](arg);