// 测试数据库连接 import pkg from 'pg'; const { Client } = pkg; async function testConnection() { // 创建PostgreSQL客户端 const client = new Client({ host: 'nas.7bm.co', port: 54302, database: 'docauditai', user: 'api_user', password: 'your_password_here', // 替换为实际密码 ssl: false // 根据需要设置SSL }); try { console.log('正在连接数据库...'); await client.connect(); console.log('连接成功!'); // 测试查询 const result = await client.query('SELECT now() as current_time'); console.log('服务器时间:', result.rows[0].current_time); // 查看数据库中的表 const tablesResult = await client.query(` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' `); console.log('数据库中的表:'); tablesResult.rows.forEach(row => { console.log(`- ${row.table_name}`); }); } catch (err) { console.error('连接或查询失败:', err); } finally { // 关闭连接 await client.end(); console.log('连接已关闭'); } } // 执行测试 testConnection();