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, 'sqlalchemy.create_engine', 'create_engine', False, 'from sqlalchemy import create_engine, engine\n'), (10, 'sqlalchemy.orm.sessionmaker', 'sessionmaker', False, 'from sqlalchemy.orm import sessionmaker\n'), (12, 'sqlalchemy.ext.declarative.declarative_base', 'declarative_base', False, 'from sqlalchemy.ext.declarative import declarative_base\n'), (6, 'os.getenv', 'os.getenv', False, 'import os\n')]