-
Notifications
You must be signed in to change notification settings - Fork 1
/
highLevelStorageWrapper.js
66 lines (46 loc) · 1.55 KB
/
highLevelStorageWrapper.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
63
64
65
66
class HighLevelStorageWrapper {
wrap(lowLevelStorage) {
let get = function (key) {
return new Promise(async (resolve, reject) => {
await lowLevelStorage.get(key, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
}
let put = function (key, value) {
return new Promise(async (resolve, reject) => {
await lowLevelStorage.put(key, value, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
}
let del = function (key) {
return new Promise(async (resolve, reject) => {
await lowLevelStorage.del(key, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
}
let batchPut = function (input) {
return new Promise(async (resolve, reject) => {
input.map(async (data, index, arr) => {
await lowLevelStorage.put(data.key, data.value, (err, data) => {
if (err) reject(err);
else resolve("Batch data added successfully");
});
});
});
}
return {
get: get,
put: put,
del: del,
batchPut: batchPut
}
}
}
let wrap = new HighLevelStorageWrapper().wrap;
module.exports = wrap;