---
title: "Discussion on \"Persistence and domain model separation using SQLAlchemy ORM\" | Hashnode"
description: "Discussion on \"Persistence and domain model separation using SQLAlchemy ORM\". In this post we show how to separate your domain model from persistance to unit test it without database setup using SQLAlchemy ORM (python)"
url: "https://hashnode.com/posts/persistence-and-domain-model-separation-using-sqlalchemy-orm/61a3f6da2be89f3d0ab9ed59"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Persistence and domain model separation using SQLAlchemy ORM](https://jorzel.hashnode.dev/persistence-and-domain-model-separation-using-sqlalchemy-orm?utm_source=hashnode&utm_medium=feed)

In this post we show how to separate your domain model from persistance to unit test it without database setup using SQLAlchemy ORM (python)

Nov 28, 2021 · 7 min read · jorzel.hashnode.dev  
Updated Aug 10, 2022  
Read the article

-   [#orm](https://hashnode.com/tag/orm)
-   [#python](https://hashnode.com/tag/python)
-   [#refactoring](https://hashnode.com/tag/refactoring)
-   [#unit-testing](https://hashnode.com/tag/unit-testing)
-   [#software-design](https://hashnode.com/tag/software-design)

## Written by

[jorzel](https://hashnode.com/@jorzel)

@jorzel · Warsaw, Poland

  
[View profile](https://hashnode.com/@jorzel)

Software Engineer at SauceLabs

Backend developer with special interest in software design, architecture and system modelling. Trying to stay in a continuous learning mindset. Enjoy refactoring, clean code, DDD philosophy and TDD approach.

## Responses 1

Markdown supported · ⌘↵ to post

[Kiriti Badam](https://hashnode.com/@kiritibadam)

[Mar 9, 2023](https://hashnode.com/posts/persistence-and-domain-model-separation-using-sqlalchemy-orm/61a3f6da2be89f3d0ab9ed59/comment/6409a00e6b5ccef6ff20efd7)

Thanks for writing this detailed blog. Have you given any thoughts about definition of a translation layer without the mapper? For example, if I have a dataclass in the domain model but I want to store that dataclass as a JSON in the persistence model.

[jorzel](https://hashnode.com/@jorzel)

[Mar 9, 2023](https://hashnode.com/posts/persistence-and-domain-model-separation-using-sqlalchemy-orm/61a3f6da2be89f3d0ab9ed59/comment/6409a00e6b5ccef6ff20efd7#reply-6409aa5f6b5ccef6ff20f254)

Maybe I have a useful example: [github.com/jorzel/recruitment/blob/main/src/infra…](https://github.com/jorzel/recruitment/blob/main/src/infrastructure/db/sqlalchemy/orm.py.) This `data` field under `StoredEvent` could be a dataclass. Instead of using a mapper (and ORM), you can exploit raw SQL (or document insert/update procedure) within infrastructure repository implementation.
