Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to Implement DDD Without ORM Mapping Functionality? #86

Open
molpako opened this issue Aug 12, 2024 · 2 comments
Open

Question: How to Implement DDD Without ORM Mapping Functionality? #86

molpako opened this issue Aug 12, 2024 · 2 comments

Comments

@molpako
Copy link

molpako commented Aug 12, 2024

https://github.com/molpako/Architecture-Patterns-with-Python

Hello, I’m using this book to study DDD. At the same time, I wanted to incorporate recent trends into my learning, so I started studying with FastAPI and sqlc.

However, since sqlc doesn’t provide object-to-table mapping functionality, I’m unsure how to solve this, and I need help.

In the book, SQLAlchemy’s mapper is used to bind the domain model to the table, and storage changes are accomplished by modifying the aggregate. sqlc is an ORM specialized in generating Go objects from raw SQL, so it doesn’t have the mapping functionality that the book uses.

Would it be appropriate to implement the functionality in the repository to reflect changes in the domain class to the DB, and then call that functionality in the service layer after making changes to the domain class? Or is it impossible to achieve DDD without an ORM that has mapping functionality?

@hjwp
Copy link
Contributor

hjwp commented Aug 16, 2024

you can absolutey do ddd without an orm, and you can build a Repository that just uses raw sql. it's more fiddly and boilerplatey, but it is also arguably more explicit and has less magic, so it's a totally valid thing to do.

you can also use an orm that's separate from your domain model -- the django appendix in the book does this -- and the repository's job is to translate from your domain model objectrs, to and from ORM objects, and to use those to load/save to the db.

@molpako
Copy link
Author

molpako commented Aug 18, 2024

Thank you for your comment! I was aware that there is an appendix about Django, but I hadn’t checked it yet… I’ll read Appendix D. Repository and Unit of Work Patterns with Django right away!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants