
Your Domain Doesn't Know About PostgreSQL (And It Shouldn't)
Your business logic shouldn't care whether you're using PostgreSQL, MySQL, or a folder full of text files. If it does that's not a minor code smell. That's an architectural problem. Let me show you what it looks like in a real codebase. A Simple Example That's Not Actually Simple Say you're building an order management system. An order has items, a total, and a status. When an order is placed, you validate it, apply a discount if the customer qualifies, and save it. Here's what that service looks like in most codebases: from sqlalchemy.orm import Session from app.models import Order , Customer from app.db import get_db from fastapi import HTTPException import os class OrderService : def place_order ( self , customer_id : int , items : list , db : Session ): customer = db . query ( Customer ). filter ( Customer . id == customer_id ). first () if not customer : raise HTTPException ( status_code = 404 , detail = " Customer not found " ) total = sum ( item [ " price " ] * item [ " qty " ]
Continue reading on Dev.to Webdev
Opens in a new tab




