Download api/tables.js from MaxLeft/psyconnect-database-explorer: direct link, hf CLI and curl.
- Browser
- Download file 903 Bytes
-
https://huggingface.co/spaces/MaxLeft/psyconnect-database-explorer/resolve/main/api/tables.js
- Command line
-
hf download hf://spaces/MaxLeft/psyconnect-database-explorer/api/tables.js
-
curl -L -o tables.js https://huggingface.co/spaces/MaxLeft/psyconnect-database-explorer/resolve/main/api/tables.js
903 Bytes
| 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' }); | |
| } | |
| }; |