MaxLeft commited on
Commit
083e043
·
verified ·
1 Parent(s): 39dfd02

Its nto giving me the tables

Browse files
Files changed (6) hide show
  1. README.md +7 -4
  2. api/tables.js +31 -0
  3. components/navbar.js +43 -0
  4. index.html +98 -19
  5. script.js +85 -0
  6. style.css +33 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Psyconnect Database Explorer
3
- emoji: 📚
4
- colorFrom: red
5
  colorTo: pink
 
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: PsyConnect Database Explorer
3
+ colorFrom: yellow
 
4
  colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
api/tables.js ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { Pool } = require('pg');
2
+
3
+ module.exports = async (req, res) => {
4
+ try {
5
+ const { host, port, user, password, dbname, sslmode } = req.body;
6
+
7
+ const pool = new Pool({
8
+ host,
9
+ port,
10
+ user,
11
+ password,
12
+ database: dbname,
13
+ ssl: sslmode === 'require' ? { rejectUnauthorized: false } : false
14
+ });
15
+
16
+ const client = await pool.connect();
17
+ const result = await client.query(`
18
+ SELECT table_name, table_schema
19
+ FROM information_schema.tables
20
+ WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
21
+ `);
22
+
23
+ client.release();
24
+ await pool.end();
25
+
26
+ res.status(200).json(result.rows);
27
+ } catch (error) {
28
+ console.error('Database error:', error);
29
+ res.status(500).json({ error: 'Failed to fetch tables' });
30
+ }
31
+ };
components/navbar.js ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomNavbar extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ .navbar {
7
+ background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
8
+ }
9
+ .nav-link {
10
+ transition: all 0.3s ease;
11
+ }
12
+ .nav-link:hover {
13
+ transform: translateY(-2px);
14
+ }
15
+ </style>
16
+ <nav class="navbar text-white shadow-lg">
17
+ <div class="container mx-auto px-4 py-4">
18
+ <div class="flex justify-between items-center">
19
+ <div class="flex items-center space-x-2">
20
+ <i data-feather="database" class="w-6 h-6"></i>
21
+ <a href="/" class="text-xl font-bold">PsyConnect</a>
22
+ </div>
23
+ <div class="hidden md:flex items-center space-x-6">
24
+ <a href="#" class="nav-link flex items-center space-x-1">
25
+ <i data-feather="home" class="w-4 h-4"></i>
26
+ <span>Dashboard</span>
27
+ </a>
28
+ <a href="#" class="nav-link flex items-center space-x-1">
29
+ <i data-feather="database" class="w-4 h-4"></i>
30
+ <span>Tables</span>
31
+ </a>
32
+ <a href="#" class="nav-link flex items-center space-x-1">
33
+ <i data-feather="terminal" class="w-4 h-4"></i>
34
+ <span>Query</span>
35
+ </a>
36
+ <a href="#" class="nav-link flex items-center space-x-1">
37
+ <i data-feather="settings" class="w-4 h-4"></i>
38
+ <span>Settings</span>
39
+ </a>
40
+ </div>
41
+ <div class="flex items-center space-x-4">
42
+ <button class="p-2 rounded-full hover:bg-white hover:bg-opacity-10 transition">
43
+ <i data-feather="bell" class
index.html CHANGED
@@ -1,19 +1,98 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>PsyConnect - Database Explorer</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <script src="https://unpkg.com/feather-icons"></script>
11
+ <script src="components/navbar.js"></script>
12
+ <script src="components/footer.js"></script>
13
+ </head>
14
+ <body class="bg-gray-50 min-h-screen flex flex-col">
15
+ <custom-navbar></custom-navbar>
16
+
17
+ <main class="flex-grow container mx-auto px-4 py-8">
18
+ <div class="max-w-4xl mx-auto">
19
+ <div class="bg-white rounded-xl shadow-md p-6 mb-8">
20
+ <h1 class="text-3xl font-bold text-gray-800 mb-6">Database Explorer</h1>
21
+
22
+ <div class="mb-8">
23
+ <div class="relative">
24
+ <input type="text" id="searchInput" placeholder="Search tables or records..."
25
+ class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent">
26
+ <i data-feather="search" class="absolute right-3 top-3 text-gray-400"></i>
27
+ </div>
28
+ </div>
29
+
30
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
31
+ <div class="bg-indigo-50 rounded-lg p-6">
32
+ <div class="flex items-center mb-4">
33
+ <div class="bg-indigo-100 p-3 rounded-full mr-4">
34
+ <i data-feather="database" class="text-indigo-600"></i>
35
+ </div>
36
+ <h2 class="text-xl font-semibold text-gray-800">Database Info</h2>
37
+ </div>
38
+ <div class="space-y-2 text-gray-600">
39
+ <p><span class="font-medium">Host:</span> pg-90c016a-mozmail-fead.i.aivencloud.com</p>
40
+ <p><span class="font-medium">Port:</span> 15173</p>
41
+ <p><span class="font-medium">User:</span> avnadmin</p>
42
+ </div>
43
+ </div>
44
+
45
+ <div class="bg-green-50 rounded-lg p-6">
46
+ <div class="flex items-center mb-4">
47
+ <div class="bg-green-100 p-3 rounded-full mr-4">
48
+ <i data-feather="activity" class="text-green-600"></i>
49
+ </div>
50
+ <h2 class="text-xl font-semibold text-gray-800">Quick Actions</h2>
51
+ </div>
52
+ <div class="grid grid-cols-2 gap-3">
53
+ <button class="bg-white text-indigo-600 px-4 py-2 rounded-lg border border-indigo-100 hover:bg-indigo-50 transition">
54
+ View Tables
55
+ </button>
56
+ <button class="bg-white text-green-600 px-4 py-2 rounded-lg border border-green-100 hover:bg-green-50 transition">
57
+ Run Query
58
+ </button>
59
+ <button class="bg-white text-purple-600 px-4 py-2 rounded-lg border border-purple-100 hover:bg-purple-50 transition">
60
+ Export Data
61
+ </button>
62
+ <button class="bg-white text-blue-600 px-4 py-2 rounded-lg border border-blue-100 hover:bg-blue-50 transition">
63
+ Schema Diagram
64
+ </button>
65
+ </div>
66
+ </div>
67
+ </div>
68
+
69
+ <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
70
+ <div class="px-6 py-4 border-b border-gray-200 bg-gray-50">
71
+ <h2 class="text-lg font-semibold text-gray-800">Tables Preview</h2>
72
+ </div>
73
+ <div class="divide-y divide-gray-200">
74
+ <!-- Tables will be dynamically inserted here -->
75
+ </div>
76
+ <div id="loading" class="p-6 text-center text-gray-500">
77
+ <i data-feather="loader" class="animate-spin inline-block"></i>
78
+ <span class="ml-2">Loading tables...</span>
79
+ </div>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ </main>
84
+
85
+ <custom-footer></custom-footer>
86
+
87
+ <script>
88
+ feather.replace();
89
+
90
+ document.getElementById('searchInput').addEventListener('input', function(e) {
91
+ console.log('Searching for:', e.target.value);
92
+ // Implement search functionality here
93
+ });
94
+ </script>
95
+ <script src="script.js"></script>
96
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
97
+ </body>
98
+ </html>
script.js ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Database connection configuration
2
+ const dbConfig = {
3
+ host: 'pg-90c016a-mozmail-fead.i.aivencloud.com',
4
+ port: 15173,
5
+ user: 'avnadmin',
6
+ password: 'AVNS_4wOfQguMcSX18XkXZYL',
7
+ dbname: 'defaultdb',
8
+ sslmode: 'require'
9
+ };
10
+ // Function to fetch tables from database
11
+ async function fetchTables() {
12
+ try {
13
+ const response = await fetch('/api/tables', {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ body: JSON.stringify(dbConfig)
19
+ });
20
+
21
+ if (!response.ok) {
22
+ throw new Error('Failed to fetch tables');
23
+ }
24
+
25
+ return await response.json();
26
+ } catch (error) {
27
+ console.error('Error fetching tables:', error);
28
+ showError('Failed to fetch tables. Please check your connection.');
29
+ return [];
30
+ }
31
+ }
32
+
33
+ // Function to display tables in UI
34
+ function displayTables(tables) {
35
+ const tablesContainer = document.querySelector('.divide-y');
36
+ if (!tablesContainer) return;
37
+
38
+ tablesContainer.innerHTML = '';
39
+
40
+ tables.forEach(table => {
41
+ const tableElement = document.createElement('div');
42
+ tableElement.className = 'p-6 hover:bg-gray-50 transition cursor-pointer';
43
+ tableElement.innerHTML = `
44
+ <div class="flex justify-between items-center">
45
+ <div>
46
+ <h3 class="font-medium text-gray-800">${table.table_name}</h3>
47
+ <p class="text-sm text-gray-500">${table.table_schema || 'No description available'}</p>
48
+ </div>
49
+ <i data-feather="chevron-right" class="text-gray-400"></i>
50
+ </div>
51
+ `;
52
+ tablesContainer.appendChild(tableElement);
53
+ });
54
+
55
+ feather.replace();
56
+ }
57
+
58
+ // Function to show error message
59
+ function showError(message) {
60
+ const errorElement = document.createElement('div');
61
+ errorElement.className = 'bg-red-50 text-red-600 p-4 rounded-lg mb-6';
62
+ errorElement.textContent = message;
63
+ document.querySelector('.max-w-4xl').prepend(errorElement);
64
+ }
65
+
66
+ // Initialize the application
67
+ document.addEventListener('DOMContentLoaded', async () => {
68
+ console.log('Application initialized');
69
+
70
+ try {
71
+ const tables = await fetchTables();
72
+ displayTables(tables);
73
+ } catch (error) {
74
+ console.error('Initialization error:', error);
75
+ showError('Failed to initialize application');
76
+ }
77
+ });
78
+ // Search functionality
79
+ document.getElementById('searchInput')?.addEventListener('input', function(e) {
80
+ const searchTerm = e.target.value.toLowerCase();
81
+ console.log('Searching for:', searchTerm);
82
+
83
+ // In a real implementation, you would filter the tables or records
84
+ // based on the search term and update the UI accordingly
85
+ });
style.css CHANGED
@@ -1,28 +1,43 @@
 
 
1
  body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
 
 
28
  }
 
 
 
 
 
1
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
2
+
3
  body {
4
+ font-family: 'Inter', sans-serif;
5
+ }
6
+
7
+ /* Custom scrollbar */
8
+ ::-webkit-scrollbar {
9
+ width: 8px;
10
+ height: 8px;
11
+ }
12
+
13
+ ::-webkit-scrollbar-track {
14
+ background: #f1f1f1;
15
+ }
16
+
17
+ ::-webkit-scrollbar-thumb {
18
+ background: #888;
19
+ border-radius: 4px;
20
  }
21
 
22
+ ::-webkit-scrollbar-thumb:hover {
23
+ background: #555;
 
24
  }
25
 
26
+ /* Animation for buttons */
27
+ .button-scale {
28
+ transition: transform 0.2s ease;
 
 
29
  }
30
 
31
+ .button-scale:hover {
32
+ transform: scale(1.02);
 
 
 
 
33
  }
34
 
35
+ /* Fade in animation */
36
+ @keyframes fadeIn {
37
+ from { opacity: 0; }
38
+ to { opacity: 1; }
39
  }
40
+
41
+ .fade-in {
42
+ animation: fadeIn 0.3s ease-in;
43
+ }