Uwev2/src/inc/cfg.js

34 lines
751 B
JavaScript
Raw Normal View History

2017-11-18 10:53:58 +00:00
import sql from "./sql.js";
2017-11-07 17:22:41 +00:00
let cfg = {
2017-11-08 20:40:59 +00:00
client: {},
2017-11-07 17:22:41 +00:00
main: {},
websrv: {},
trigger: {}
};
const read = () => new Promise((resolve, reject) => {
sql.exec("select * from `cfg`", (err, rows) => {
if(err || rows.length < 1)
reject({ error: "no cfg" });
else {
for(let row in rows) {
2017-11-08 20:40:59 +00:00
cfg[rows[row].class][rows[row].key] = ((type, value) => {
2017-11-07 17:22:41 +00:00
switch(type) {
2017-11-18 10:53:58 +00:00
case "string":
return value;
case "int":
return parseInt(value);
case "bool":
return value === "true";
case "json":
return JSON.parse(value);
2017-11-07 17:22:41 +00:00
}
})(rows[row].type, rows[row].value);
}
resolve();
}
});
});
export { cfg, read };