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

# Configuração do banco de dados
DATABASE_URL = os.getenv('DATABASE_URL', 'sqlite:///database.db')
engine = create_engine(DATABASE_URL)
Session = sessionmaker(bind=engine)

# Base declarativa do SQLAlchemy
Base = declarative_base()

def get_db_connection():
    """Retorna uma nova sessão do banco de dados"""
    session = Session()
    try:
        return session
    except Exception as e:
        session.rollback()
        raise e 