const mysql = require('mysql2/promise');
const fs = require('fs');

async function main() {
    const conn = await mysql.createConnection({
        host: '175.103.40.219',
        port: 3307,
        user: 'root',
        password: 'S@pAbadi**ICT',
        database: 'sapharmaco_sapps'
    });
    const [rows] = await conn.execute(
        "SELECT id, name, url, parent_id FROM menus WHERE url LIKE '%assets%' OR url LIKE '%license%' OR url LIKE '%accessor%' OR url LIKE '%consumab%' ORDER BY parent_id, id"
    );
    const out = rows.map(r => `${r.id} | parent:${r.parent_id} | ${r.name} | ${r.url}`).join('\n');
    fs.writeFileSync('./menu_results.txt', out);
    console.log('Written to menu_results.txt');
    console.log(out);
    await conn.end();
    process.exit(0);
}
main().catch(e => { console.error(e.message); process.exit(1); });
