-
Notifications
You must be signed in to change notification settings - Fork 18
/
getPathObj.js
56 lines (52 loc) · 1.39 KB
/
getPathObj.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
const { store } = require("./index");
function getPathObj(path) {
return new Promise(function(resolve, reject) {
store.get(path, function(err, obj) {
if (err) {
console.log(path)
resolve({});
} else {
resolve(obj);
}
});
});
}
exports.getPathObj = getPathObj;
function getPathNum(path) {
return new Promise(function(resolve, reject) {
store.get(path, function(err, obj) {
if (err) {
reject(err);
} else {
if (typeof obj != 'number') {
resolve(0);
} else {
resolve(obj);
}
}
});
});
}
exports.getPathNum = getPathNum;
function getPathSome(path, arg) {
return new Promise(function(resolve, reject) {
store.someChildren(path, arg, function(err, obj) {
if (err) {
reject(err);
resolve({})
} else {
resolve(obj);
}
});
});
}
exports.getPathSome = getPathSome;
exports.deleteObjs = (paths) => {
return new Promise((resolve, reject) => {
var ops = [];
for (i = 0; i < paths.length; i++) {
ops.push({ type: 'del', path: paths[i] });
}
store.batch(ops, [resolve, reject, paths.length]);
})
}