# app/api/db/database.py from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker # Configure SQLite database SQLALCHEMY_DATABASE_URL = "sqlite:///./blog_app.db" # Create the SQLAlchemy engine engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} ) # Create a SessionLocal class for database sessions SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) # Create a Base class for models Base = declarative_base() ``` This code defines the necessary components for interacting with a SQLite database using SQLAlchemy in a FastAPI application named `blog_app`. This `database.py` file should be placed in the `app/api/db/` directory of the FastAPI project, following the recommended project structure.