Files
nxxmdata/backend/count-data.js
2025-08-25 15:00:46 +08:00

26 lines
749 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { sequelize } = require('./config/database-simple');
async function countData() {
try {
await sequelize.authenticate();
console.log('数据库连接成功\n');
// 检查各表的数据量
const tables = ['farms', 'animals', 'devices', 'alerts', 'sensor_data'];
console.log('=== 数据统计 ===');
for (const table of tables) {
const [results] = await sequelize.query(`SELECT COUNT(*) as count FROM ${table}`);
console.log(`${table.padEnd(12)}: ${results[0].count.toString().padStart(6)} 条记录`);
}
console.log('\n数据导入完成');
} catch (error) {
console.error('统计失败:', error.message);
} finally {
await sequelize.close();
}
}
countData();