-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-db-connection.mjs
More file actions
30 lines (24 loc) · 897 Bytes
/
Copy pathtest-db-connection.mjs
File metadata and controls
30 lines (24 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import postgres from 'postgres';
const connectionString = process.env.DATABASE_URL || process.env.ideas_DATABASE_URL || process.env.POSTGRES_URL;
if (!connectionString) {
console.error('Set DATABASE_URL (or ideas_DATABASE_URL / POSTGRES_URL) in your environment');
process.exit(1);
}
console.log('Testing database connection...');
try {
// Try with default settings first
const client = postgres(connectionString, {
connect_timeout: 30,
idle_timeout: 30,
});
const result = await client`SELECT version(), current_database()`;
console.log('✅ Connected successfully!');
console.log('PostgreSQL version:', result[0].version);
console.log('Database:', result[0].current_database);
await client.end();
process.exit(0);
} catch (error) {
console.error('❌ Connection failed:', error.message);
console.error('Error code:', error.code);
process.exit(1);
}