const { Client } = require('pg'); const fs = require('fs'); async function main() { const client = new Client({ host: '39.98.38.2', port: 5866, database: 'highgo', user: 'highgo', password: 'Gw@141516', connectionTimeoutMillis: 30000, }); try { await client.connect(); console.log('Connected to database'); // Get all tables in slaj schema const tableRes = await client.query(` SELECT table_name FROM information_schema.tables WHERE table_schema = 'slaj' AND table_type = 'BASE TABLE' ORDER BY table_name `); const tableNames = tableRes.rows.map(r => r.table_name); console.log(`Total tables in slaj schema: ${tableNames.length}`); // Get columns for each table const dbTables = {}; for (const tname of tableNames) { const colRes = await client.query(` SELECT column_name, data_type, COALESCE(character_maximum_length, numeric_precision) AS max_length, is_nullable, column_default FROM information_schema.columns WHERE table_schema = 'slaj' AND table_name = $1 ORDER BY ordinal_position `, [tname]); const cols = colRes.rows.map(c => ({ name: c.column_name.toUpperCase(), type: c.data_type.toUpperCase(), nullable: c.is_nullable === 'YES', default: c.column_default, })); dbTables[tname] = cols; } // Save to JSON fs.writeFileSync('d:/Workspaces/slaj/_slaj_db_tables.json', JSON.stringify(dbTables, null, 2)); console.log(`Saved ${Object.keys(dbTables).length} tables to _slaj_db_tables.json`); // Print table list console.log('\n=== 安监数据库 slaj schema 表列表 ==='); for (const tname of Object.keys(dbTables).sort()) { console.log(`${tname} (${dbTables[tname].length} cols)`); } await client.end(); } catch (err) { console.error('Error:', err.message); process.exit(1); } } main();