from sqlalchemy import create_engine, engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import os

SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL").replace("postgres://", "postgresql+psycopg2://")

engine = create_engine(SQLALCHEMY_DATABASE_URL)

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()


def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

[((8, 9, 8, 47), 'sqlalchemy.create_engine', 'create_engine', ({(8, 23, 8, 46): 'SQLALCHEMY_DATABASE_URL'}, {}), '(SQLALCHEMY_DATABASE_URL)', False, 'from sqlalchemy import create_engine, engine\n'), ((10, 15, 10, 75), 'sqlalchemy.orm.sessionmaker', 'sessionmaker', (), '', False, 'from sqlalchemy.orm import sessionmaker\n'), ((12, 7, 12, 25), 'sqlalchemy.ext.declarative.declarative_base', 'declarative_base', ({}, {}), '()', False, 'from sqlalchemy.ext.declarative import declarative_base\n'), ((6, 26, 6, 51), 'os.getenv', 'os.getenv', ({(6, 36, 6, 50): '"""DATABASE_URL"""'}, {}), "('DATABASE_URL')", False, 'import os\n')]