const { Client } = require('pg');
const client = new Client({
    host: '87.106.21.21',
    port: 5432,
    user: 'enwelo_admin',
    password: 'WX1t1cgP1qK09',
    database: 'enwelo'
});
client.connect().then(async () => {
    try {
        console.log("--- Sample from flaecheneigentuemer_alkis ---");
        const alkis = await client.query('SELECT "GNA", "VNA", "FSK" FROM geodaten.flaecheneigentuemer_alkis LIMIT 5');
        console.log("Keys in result row:", Object.keys(alkis.rows[0]));
        console.table(alkis.rows);

        console.log("\n--- Sample from flaecheneigentuemer_alkis_zuweisung ---");
        const zuweisung = await client.query('SELECT * FROM geodaten.flaecheneigentuemer_alkis_zuweisung LIMIT 5');
        console.table(zuweisung.rows);

        console.log("\n--- Checking if names match exactly ---");
        // Try a name search with LOWER for testing
        const nameSearch = await client.query('SELECT count(*) FROM geodaten.flaecheneigentuemer_alkis WHERE "GNA" = $1', [alkis.rows[0].GNA]);
        console.log(`Searching for "${alkis.rows[0].GNA}": found ${nameSearch.rows[0].count} entries.`);

    } catch (e) {
        console.error(e);
    } finally {
        client.end();
    }
});
