const { Client } = require('pg');

async function testQuery() {
    require('dotenv').config({ path: '../.env' });
const client = new Client({
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME
});
    
    try {
        await client.connect();
        const nachname = '';
        const vorname = 'Anja';
        
        console.log(`Querying for GNA='${nachname}' AND VNA='${vorname}'`);
        const res1 = await client.query(
            `SELECT "FSK" FROM geodaten.flaecheneigentuemer_alkis WHERE "GNA" = $1 AND "VNA" = $2`,
            [nachname, vorname]
        );
        console.log(`Found: ${res1.rowCount} rows.`);

        console.log(`Querying for (GNA=$1 OR (GNA IS NULL AND $1='')) AND VNA=$2`);
        const res2 = await client.query(
            `SELECT "FSK" FROM geodaten.flaecheneigentuemer_alkis 
             WHERE ("GNA" = $1 OR ("GNA" IS NULL AND $1 = '')) 
             AND ("VNA" = $2 OR ("VNA" IS NULL AND $2 = ''))`,
            [nachname, vorname]
        );
        console.log(`Found: ${res2.rowCount} rows.`);

    } catch (e) {
        console.error("Error:", e);
    } finally {
        await client.end();
    }
}
testQuery();
