bwsamern-ohne_standortplaner/backend/test_art.js

41 lines
1.2 KiB
JavaScript

require('dotenv').config({ path: '../.env' });
const { Pool } = require('pg');
const pool = new Pool({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
});
async function run() {
try {
const res = await pool.query("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'geodaten' AND table_name = 'artennachweis'");
console.log("Columns:", res.rows);
// Test the exact query
const res2 = await pool.query(`SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', COALESCE(jsonb_agg(features.feature), '[]'::jsonb)
)
FROM (
SELECT jsonb_build_object(
'type', 'Feature',
'geometry', ST_AsGeoJSON(ST_Transform(geom, 4326))::jsonb,
'properties', jsonb_build_object(
'art', art
)
) AS feature
FROM geodaten.artennachweis
) features`);
console.log("Query Success! First few chars of result:", JSON.stringify(res2.rows[0]).substring(0, 100));
} catch (err) {
console.error("Error:", err.message);
} finally {
pool.end();
}
}
run();