Files
BetterDesk/web-nodejs/test-db.js
T
UNITRONIX 00451634c7 Await DB operations in route handlers
Convert many Express route handlers and helper functions to async and await database calls (e.g. getAccessToken, touchAccessToken, getPeerById, getDevice, getPeerSysinfo, upsertPeerSysinfo, logAction, insertAudit*, getAll*/count* etc.). Also made identifyDevice and several route callbacks async, adjusted session.regenerate callback to use async logging, and replaced db.getDatabase() usage with db.getDb() where applicable. These changes ensure DB operations complete before responding and reduce race conditions/unhandled-promise behavior across numerous route files (activity, auth, automation, bd-api, devices, folders, i18n, inventory, registration, remote, rustdesk-api, and related route handlers).

Co-Authored-By: Charles Olivier Savignac <1275666+sircharlo@users.noreply.github.com>
2026-03-03 22:57:10 +01:00

35 lines
1.1 KiB
JavaScript

const config = require('./config/config');
const db = require('./services/database');
console.log('Config:');
console.log(' DB_PATH:', config.dbPath);
console.log(' DATA_DIR:', config.dataDir);
console.log(' KEYS_PATH:', config.keysPath);
console.log(' DB_TYPE:', db.DB_TYPE || 'sqlite');
console.log('');
(async () => {
try {
await db.init();
const devices = await db.getAllDevices({});
console.log('Total devices:', devices.length);
console.log('Type:', typeof devices);
console.log('Is array:', Array.isArray(devices));
if (devices.length > 0) {
console.log('First device:', JSON.stringify(devices[0], null, 2));
}
const stats = await db.getStats();
console.log('Stats:', JSON.stringify(stats, null, 2));
const auditLogs = await db.getAuditLogs(5);
console.log('Audit logs:', JSON.stringify(auditLogs, null, 2));
} catch (err) {
console.error('Error:', err.message);
console.error('Stack:', err.stack);
} finally {
await db.close();
}
})();