43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import mysql from 'mysql2/promise';
|
|
|
|
async function checkData() {
|
|
const dbConfig = {
|
|
host: 'localhost',
|
|
user: 'root',
|
|
password: '',
|
|
database: 'sis_odonto'
|
|
};
|
|
|
|
try {
|
|
const connection = await mysql.createConnection(dbConfig);
|
|
console.log('Connected to MySQL');
|
|
|
|
const [dentists] = await connection.query('SELECT * FROM dentistas');
|
|
console.log('\n--- DENTISTAS ---');
|
|
console.table(dentists.map(d => ({ id: d.id, nome: d.nome })));
|
|
|
|
const [agendamentos] = await connection.query('SELECT * FROM agendamentos');
|
|
console.log('\n--- AGENDAMENTOS (Counts per Dentist) ---');
|
|
const counts = {};
|
|
agendamentos.forEach(a => {
|
|
counts[a.dentistaId] = (counts[a.dentistaId] || 0) + 1;
|
|
});
|
|
|
|
const countsTable = Object.entries(counts).map(([id, count]) => {
|
|
const d = dentists.find(dentist => dentist.id === id);
|
|
return {
|
|
dentistId: id,
|
|
nome: d ? d.nome : 'UNKNOWN (Maybe deleted or not assigned)',
|
|
count: count
|
|
};
|
|
});
|
|
console.table(countsTable);
|
|
|
|
await connection.end();
|
|
} catch (err) {
|
|
console.error('Error:', err.message);
|
|
}
|
|
}
|
|
|
|
checkData();
|