Automated Action 0a65bff5f3 Implement invoice generation service
- Create FastAPI app structure
- Set up SQLAlchemy with SQLite for database management
- Implement invoice and invoice item models
- Add Alembic for database migrations
- Create invoice generation and retrieval API endpoints
- Add health check endpoint
- Set up Ruff for linting
- Update README with project details
2025-05-18 20:01:08 +00:00

29 lines
645 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Setup database directory
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()