require('dotenv').config();
const { Client } = require('pg');

const client = new Client({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME,
    port: process.env.DB_PORT,
});

(async () => {
    try {
        await client.connect();
        console.log('Listing tables in database...');
        const res = await client.query(`
            SELECT table_name 
            FROM information_schema.tables 
            WHERE table_schema = 'public'
            ORDER BY table_name;
        `);
        console.log(res.rows.map(r => r.table_name));
        await client.end();
    } catch (err) {
        console.error(err);
        process.exit(1);
    }
})();
