Standortplaner/backend/check_assignments.js

37 lines
1.1 KiB
JavaScript

const { Client } = require('pg');
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
});
client.connect().then(async () => {
try {
const res = await client.query(`
SELECT
a."VNA", a."GNA", a."FSK",
z.projekt_id IS NOT NULL as is_assigned
FROM geodaten.flaecheneigentuemer_alkis a
LEFT JOIN geodaten.flaecheneigentuemer_alkis_zuweisung z ON a."FSK" = z.fsk
LIMIT 20
`);
console.table(res.rows);
const summary = await client.query(`
SELECT
count(*) as total,
count(z.fsk) as assigned
FROM geodaten.flaecheneigentuemer_alkis a
LEFT JOIN geodaten.flaecheneigentuemer_alkis_zuweisung z ON a."FSK" = z.fsk
`);
console.log("Summary:", summary.rows[0]);
} catch (e) {
console.error(e);
} finally {
client.end();
}
});