本文整理汇总了TypeScript中lokijs.loadDatabase函数的典型用法代码示例。如果您正苦于以下问题:TypeScript loadDatabase函数的具体用法?TypeScript loadDatabase怎么用?TypeScript loadDatabase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadDatabase函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateBoostCool
export function updateBoostCool(req: express.Request, res: express.Response) {
var value = null;
if (req.query.Enabled == "1") {
value = (new Date()).toJSON();
}
var db = new loki('panel.json');
db.loadDatabase({}, function () {
var panel = null;
try {
var panel = db.getCollection("panel").get(1);
}
catch (ex) {
updateBoostCool(req, res);
return;
}
if (value == null) {
panel.coolOverRide = value;
}
else {
panel.heatOverRide = null;
panel.coolOverRide = value;
}
panel = ProcessPanel(panel);
db.save();
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ panel: panel }));
});
}
示例2: setupDB
function setupDB() {
var db = new loki('panel.json')
db.loadDatabase({}, function () {
if (db.collections.length == 1 && db.getCollection("panel").data.length == 1) {
var panel = db.getCollection("panel").get(1);
panel.os = os.platform();
panel.fanOn = false;
panel.heatOn = false;
panel.coolOn = false;
panel = ProcessPanel(panel);
panel.date = new Date();
db.save();
setTimeout(update, 1000);
} else {
var children = db.addCollection('panel')
var schedule = new Array();
for (var i = 0; i < (4 * 24); i++) {
var interval: any = {};
interval.on = false;
interval.temperature = 0;
schedule.push(interval);
}
if (children.count() > 0)
return;
children.insert({ fanOn: false, heatOn: false, coolOn : false, heatEnabled: 1, coolEnabled: 1, scheduleOn: 0, temperature: 80, setTemperature: 75, coolOverRide: null, heatOverRide: null, schedule: schedule, state: "" })
var panel = children.get(1);
panel = ProcessPanel(panel);
panel.os = os.platform();
panel.date = new Date();
db.save();
setTimeout(update, 1000);
}
});
}
示例3: update
function update(sense) {
var db = new loki('panel.json');
db.loadDatabase({}, function () {
var panel = null;
try {
var panel = db.getCollection("panel").get(1);
}
catch (ex) {
update(sensorLib);
return;
}
if (panel.os == "linux") {
var sensorLib = sense;
if (sense == null) {
sensorLib = require("node-dht-sensor");
sensorLib.initialize(22, 4);
}
var readout = sensorLib.read();
console.log('Temperature: ' + ((readout.temperature.toFixed(2) * 9/5) + 32) + 'C, ' + 'humidity: ' + readout.humidity.toFixed(2) + '%');
panel.temperature = Math.round((readout.temperature.toFixed(2) * 9 / 5) + 32);
}
panel = ProcessPanel(panel);
panel.date = new Date();
db.save();
setTimeout(function () { update(sensorLib) }, 5000);
});
}
示例4: settings
export function settings(req: express.Request, res: express.Response) {
var db = new loki('panel.json');
db.loadDatabase({}, function () {
var panel = null;
try {
var panel = db.getCollection("panel").get(1);
}
catch (ex) {
settings(req, res);
return;
}
res.render('settings', { panel: JSON.stringify(panel) });
});
}
示例5: getPanelState
export function getPanelState(req: express.Request, res: express.Response) {
var db = new loki('panel.json');
db.loadDatabase({}, function () {
var panel = null;
try {
var panel = db.getCollection("panel").get(1);
}
catch (ex) {
getPanelState(req, res);
return;
}
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ panel: panel }));
});
};
示例6: updateScheduleEnabled
export function updateScheduleEnabled(req: express.Request, res: express.Response) {
var db = new loki('panel.json');
db.loadDatabase({}, function () {
var panel = null;
try {
var panel = db.getCollection("panel").get(1);
}
catch (ex) {
updateScheduleEnabled(req, res);
return;
}
panel.scheduleOn = req.query.Enabled;
panel = ProcessPanel(panel);
db.save();
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ panel: panel }));
});
}
示例7: updateTemperature
export function updateTemperature(req: express.Request, res: express.Response) {
var db = new loki('panel.json');
db.loadDatabase({}, function () {
var panel = null;
try {
var panel = db.getCollection("panel").get(1);
}
catch (ex) {
updateTemperature(req, res);
return;
}
panel.setTemperature = parseInt(req.query.temperature);
panel.coolOverRide = null;
panel.heatOverRide = null;
panel.scheduleOn = 0;
panel = ProcessPanel(panel);
db.save();
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ panel: panel }));
});
}
示例8: Promise
return new Promise(resolve => {
db.loadDatabase({}, () => {
const _collection = db.getCollection(colName) || db.addCollection(colName)
resolve(_collection)
})
})