File size: 903 Bytes
083e043
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { Pool } = require('pg');

module.exports = async (req, res) => {
    try {
        const { host, port, user, password, dbname, sslmode } = req.body;

        const pool = new Pool({
            host,
            port,
            user,
            password,
            database: dbname,
            ssl: sslmode === 'require' ? { rejectUnauthorized: false } : false
        });

        const client = await pool.connect();
        const result = await client.query(`
            SELECT table_name, table_schema 
            FROM information_schema.tables 
            WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
        `);
        
        client.release();
        await pool.end();

        res.status(200).json(result.rows);
    } catch (error) {
        console.error('Database error:', error);
        res.status(500).json({ error: 'Failed to fetch tables' });
    }
};