Skip to content

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

Description

@molpako

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?

Activity

  1. hjwp commented on Aug 16, 2024

    @hjwp
    Contributor

    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.

  2. molpako commented on Aug 18, 2024

    @molpako
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions