SQLAlchemy ORM & Dependency Inversion

I’m struggling to couple SQLAlchemy ORM with a dependency inversion principle in Python.
I have an object which I want to save to DB, load from DB and this works perfectly fine with SQLA ORM. But I can’t use ORM classes with my business logic without ruining dependency inversion – they are too ORM-specific. I can cast ORM objects to business-logic objects using some interface, but this breaks ORM "update objects in DB seamlessly" functionality and is a complete mess.

Are there any direct and clean ways to solve this problem, or do I have to sacrifice ORM or DI?

Source: Python Questions

LEAVE A COMMENT