Automated Action f2d3f2d55c Create FastAPI REST API with Python and SQLite
- Implemented user authentication with JWT
- Added CRUD operations for users and items
- Setup database connection with SQLAlchemy
- Added migration scripts for easy database setup
- Included health check endpoint for monitoring

generated with BackendIM... (backend.im)
2025-05-13 18:33:54 +00:00

25 lines
630 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pathlib import Path
# Define 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()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()