forked from debugtitan/buddy-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdb.py
More file actions
23 lines (17 loc) · 665 Bytes
/
testdb.py
File metadata and controls
23 lines (17 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from sqlalchemy import create_engine, text
def test_detailed_connection():
database_url = os.getenv("DATABASE_URL")
if not database_url:
return "DATABASE_URL is not set"
try:
# Try SQLAlchemy connection
engine = create_engine(database_url)
with engine.connect() as connection:
result = connection.execute(text("SELECT version()"))
version = result.scalar()
return f"Connection successful! Database version: {version}"
except Exception as e:
return f"Connection failed: {str(e)}"
if __name__ == "__main__":
test_detailed_connection()