We keep getting the error:
Browse filesFailed to fetch tables. Using default table.
Make sure you are using the right credentials
host='pg-90c016a-mozmail-fead.i.aivencloud.com',
port=15173,
user='avnadmin',
password='AVNS_4wOfQguMcSX18XkXZYL',
dbname='defaultdb',
sslmode='require'
- index.html +1 -1
- script.js +35 -10
index.html
CHANGED
|
@@ -92,7 +92,7 @@
|
|
| 92 |
// Implement search functionality here
|
| 93 |
});
|
| 94 |
</script>
|
| 95 |
-
<script src="script.js"></script>
|
| 96 |
<script src="components/documents-table.js"></script>
|
| 97 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 98 |
</body>
|
|
|
|
| 92 |
// Implement search functionality here
|
| 93 |
});
|
| 94 |
</script>
|
| 95 |
+
<script type="module" src="script.js"></script>
|
| 96 |
<script src="components/documents-table.js"></script>
|
| 97 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 98 |
</body>
|
script.js
CHANGED
|
@@ -3,17 +3,36 @@
|
|
| 3 |
const dbTables = [
|
| 4 |
{ table_name: 'documents', table_schema: 'Stores all document records' }
|
| 5 |
];
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
async function fetchTables() {
|
| 8 |
try {
|
| 9 |
-
//
|
| 10 |
-
const
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
} catch (error) {
|
| 15 |
-
console.error('
|
| 16 |
-
showError(
|
| 17 |
return dbTables;
|
| 18 |
}
|
| 19 |
}
|
|
@@ -55,12 +74,18 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
| 55 |
|
| 56 |
const loading = document.getElementById('loading');
|
| 57 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
const tables = await fetchTables();
|
| 59 |
displayTables(tables);
|
| 60 |
} catch (error) {
|
| 61 |
console.error('Initialization error:', error);
|
| 62 |
-
showError(
|
| 63 |
-
displayTables(
|
| 64 |
} finally {
|
| 65 |
if (loading) loading.style.display = 'none';
|
| 66 |
}
|
|
|
|
| 3 |
const dbTables = [
|
| 4 |
{ table_name: 'documents', table_schema: 'Stores all document records' }
|
| 5 |
];
|
| 6 |
+
|
| 7 |
+
// Database connection config
|
| 8 |
+
const dbConfig = {
|
| 9 |
+
host: 'pg-90c016a-mozmail-fead.i.aivencloud.com',
|
| 10 |
+
port: 15173,
|
| 11 |
+
user: 'avnadmin',
|
| 12 |
+
password: 'AVNS_4wOfQguMcSX18XkXZYL',
|
| 13 |
+
database: 'defaultdb',
|
| 14 |
+
ssl: { rejectUnauthorized: false }
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
// Function to fetch tables using direct PostgreSQL connection
|
| 18 |
async function fetchTables() {
|
| 19 |
try {
|
| 20 |
+
// Load pg module dynamically
|
| 21 |
+
const { Client } = await import('pg');
|
| 22 |
+
const client = new Client(dbConfig);
|
| 23 |
+
|
| 24 |
+
await client.connect();
|
| 25 |
+
const res = await client.query(`
|
| 26 |
+
SELECT table_name, table_schema
|
| 27 |
+
FROM information_schema.tables
|
| 28 |
+
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
|
| 29 |
+
`);
|
| 30 |
+
await client.end();
|
| 31 |
+
|
| 32 |
+
return res.rows.length ? res.rows : dbTables;
|
| 33 |
} catch (error) {
|
| 34 |
+
console.error('Database connection error:', error);
|
| 35 |
+
showError(`Failed to fetch tables: ${error.message}. Using default table.`);
|
| 36 |
return dbTables;
|
| 37 |
}
|
| 38 |
}
|
|
|
|
| 74 |
|
| 75 |
const loading = document.getElementById('loading');
|
| 76 |
try {
|
| 77 |
+
// Load pg module only when needed
|
| 78 |
+
if (!window.pg) {
|
| 79 |
+
const pg = await import('https://cdn.jsdelivr.net/npm/pg@8.11.3/+esm');
|
| 80 |
+
window.pg = pg;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
const tables = await fetchTables();
|
| 84 |
displayTables(tables);
|
| 85 |
} catch (error) {
|
| 86 |
console.error('Initialization error:', error);
|
| 87 |
+
showError(`Failed to initialize application: ${error.message}. Using demo data.`);
|
| 88 |
+
displayTables(dbTables);
|
| 89 |
} finally {
|
| 90 |
if (loading) loading.style.display = 'none';
|
| 91 |
}
|