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()

[((263, 301), 'sqlalchemy.create_engine', 'create_engine', (['SQLALCHEMY_DATABASE_URL'], {}), '(SQLALCHEMY_DATABASE_URL)\n', (276, 301), False, 'from sqlalchemy import create_engine, engine\n'), ((318, 378), 'sqlalchemy.orm.sessionmaker', 'sessionmaker', ([], {'autocommit': '(False)', 'autoflush': '(False)', 'bind': 'engine'}), '(autocommit=False, autoflush=False, bind=engine)\n', (330, 378), False, 'from sqlalchemy.orm import sessionmaker\n'), ((387, 405), 'sqlalchemy.ext.declarative.declarative_base', 'declarative_base', ([], {}), '()\n', (403, 405), False, 'from sqlalchemy.ext.declarative import declarative_base\n'), ((178, 203), 'os.getenv', 'os.getenv', (['"""DATABASE_URL"""'], {}), "('DATABASE_URL')\n", (187, 203), False, 'import os\n')]