-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_db_session_mode.py
More file actions
30 lines (24 loc) · 885 Bytes
/
test_db_session_mode.py
File metadata and controls
30 lines (24 loc) · 885 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 asyncio
import os
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy import text
from dotenv import load_dotenv
load_dotenv("backend/.env")
DATABASE_URL = os.getenv("DATABASE_URL")
# Force port 5432
DATABASE_URL = DATABASE_URL.replace(":6543", ":5432")
print(f"Testing DATABASE_URL: {DATABASE_URL}")
async def test_connection():
try:
engine = create_async_engine(
DATABASE_URL,
echo=True,
connect_args={"ssl": "require"} # No need for cache disable in session mode
)
async with engine.connect() as conn:
result = await conn.execute(text("SELECT 1"))
print(f"Connection Successful! Result: {result.scalar()}")
except Exception as e:
print(f"Connection Failed: {e}")
if __name__ == "__main__":
asyncio.run(test_connection())