
- Set up project structure - Configure SQLite database with SQLAlchemy - Create item model and schema - Set up Alembic for database migrations - Implement CRUD operations for items - Add health check endpoint - Add API documentation - Configure Ruff for linting - Update README with project information
26 lines
653 B
Python
26 lines
653 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from app.core.config import settings
|
|
|
|
# Create SQLite engine
|
|
engine = create_engine(
|
|
settings.SQLALCHEMY_DATABASE_URL,
|
|
connect_args={"check_same_thread": False} # SQLite specific argument
|
|
)
|
|
|
|
# Create sessionmaker for database sessions
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# Create a base class for SQLAlchemy models
|
|
Base = declarative_base()
|
|
|
|
|
|
# Dependency to get DB session
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |