<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: dan</title>
    <description>The latest articles on DEV Community by dan (@_638ecc49d8bc398677412).</description>
    <link>https://dev.to/_638ecc49d8bc398677412</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3654712%2F89adab2b-1c8b-4d0e-b476-13f24b3467c6.png</url>
      <title>DEV Community: dan</title>
      <link>https://dev.to/_638ecc49d8bc398677412</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_638ecc49d8bc398677412"/>
    <language>en</language>
    <item>
      <title>Reducing SQLAlchemy CRUD Boilerplate with a Type-Safe Repository Pattern</title>
      <dc:creator>dan</dc:creator>
      <pubDate>Wed, 10 Dec 2025 05:40:18 +0000</pubDate>
      <link>https://dev.to/_638ecc49d8bc398677412/reducing-sqlalchemy-crud-boilerplate-with-a-type-safe-repository-pattern-4ifk</link>
      <guid>https://dev.to/_638ecc49d8bc398677412/reducing-sqlalchemy-crud-boilerplate-with-a-type-safe-repository-pattern-4ifk</guid>
      <description>&lt;p&gt;I’ve been working with FastAPI + SQLAlchemy, and one thing that always slowed our team down was the amount of repetitive CRUD boilerplate we had to write for each model.&lt;/p&gt;

&lt;p&gt;Most existing solutions didn’t fully support:&lt;br&gt;
SQLAlchemy 2.x style&lt;br&gt;
Pydantic v2&lt;br&gt;
proper mypy type inference&lt;br&gt;
a clean Repository abstraction&lt;br&gt;
So I built a small library that wraps SQLAlchemy ORM/Core queries with a generic, type-safe Repository layer.&lt;/p&gt;

&lt;p&gt;Usage example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class UserFilter(BaseRepoFilter):
    id: str | None = None

class UserRepo(BaseRepository[UserModel, UserSchema]):
    filter_class = UserFilter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;typed CRUD&lt;/li&gt;
&lt;li&gt;async support&lt;/li&gt;
&lt;li&gt;filtering with a Query DSL&lt;/li&gt;
&lt;li&gt;optional domain/schema mapping&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It already reduced a lot of boilerplate for us.&lt;br&gt;
If you’re using SQLAlchemy heavily, I’d love feedback or suggestions.&lt;/p&gt;

&lt;p&gt;Repo: &lt;strong&gt;&lt;a href="https://github.com/4jades/base-repository" rel="noopener noreferrer"&gt;https://github.com/4jades/base-repository&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>fastapi</category>
      <category>sqlalchemy</category>
      <category>python</category>
    </item>
  </channel>
</rss>
