const mysql = require('mysql2/promise');
require('dotenv').config();

async function test() {
    const url = process.env.DATABASE_URL.replace('mysql://', '');
    const [auth, hostPortDb] = url.split('@');
    const [user, password] = auth.split(':');
    const [hostPort, database] = hostPortDb.split('/');
    const [host, port] = hostPort.split(':');

    console.log(`Connecting to ${host}:${port || 3306} as ${user}...`);
    try {
        const connection = await mysql.createConnection({
            host: host,
            port: port || 3306,
            user: user,
            password: password || '',
            database: database.split('?')[0]
        });
        console.log('Connected!');
        const [rows] = await connection.execute('SELECT COUNT(*) as count FROM client');
        console.log('Client count:', rows[0].count);
        await connection.end();
    } catch (error) {
        console.error('Connection failed:', error);
    }
}

test();
