Spaces:
Runtime error
Runtime error
File size: 922 Bytes
2f88c81 |
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 os
import urllib.parse as up
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
# Parse the DATABASE_URL using urllib.parse
up.uses_netloc.append("postgres")
url = up.urlparse(
"postgres://xphzyodo:[email protected]/xphzyodo")
# Create the connection string
conn_string = f'postgresql+psycopg2://{url.username}:{url.password}@{url.hostname}/{url.path[1:]}'
# Create the engine using the connection string
engine = sa.create_engine(conn_string)
# Reassign the engine to your existing engine variable
engine = engine
# Create the session factory
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Reassign the session factory to your existing SessionLocal variable
SessionLocal = SessionLocal
# Reassign the Base to your existing Base variable
Base = declarative_base()
|