Automated Action cbb631170b Create a quick and simple FastAPI application with SQLite
This commit includes:
- Basic project structure with FastAPI
- SQLite database integration using SQLAlchemy
- CRUD API for items
- Alembic migrations setup
- Health check endpoint
- Proper error handling
- Updated README with setup instructions
2025-06-06 00:29:59 +00:00

28 lines
669 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Create DB directory
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
# Define SQLAlchemy database URL
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Define dependency to get DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()