-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
63 lines (54 loc) · 1.03 KB
/
logic.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//use lowDB to save data
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json')
const db = low(adapter)
// Set some defaults (required if your JSON file is empty)
db.defaults({ values: []})
.write()
/**
* @function [addContact]
* @returns {String} Status
*/
const add = (key,value) => {
db.get('values')
.push({ key: key, value: value})
.write()
console.info('New key/value pair added');
};
/**
* @function [get]
* @returns {String} value
*/
const get = (key) => {
var result = db.get('values')
.find({ key: key })
.value()
console.info(result);
}
/**
* @function [remove]
* @returns {String} status
*/
const remove = (key) => {
var status= db.get('values')
.remove({ key: key })
.write()
console.info("removed! " + status);
}
/**
* @function [list]
* @returns values
*/
const list = () => {
var values = db.get('values')
.value()
console.info(values);
}
// Export all methods
module.exports = {
add,
list,
get,
remove
};