Skip to content

Instantly share code, notes, and snippets.

View jarri-abidi's full-sized avatar
🇵🇸

Jarri Abidi jarri-abidi

🇵🇸
View GitHub Profile
@jarri-abidi
jarri-abidi / cqrs-query-pattern.md
Last active May 6, 2026 07:29
Keeping Your Domain Clean: A CQRS-Inspired Query Pattern in Go

Keeping Your Domain Clean: A CQRS-Inspired Query Pattern in Go

The repository pattern gets you far. It keeps your persistence logic behind a clean interface, your domain entities free of database concerns, and your application code easy to test. Most services start here and it works well — until you need to fetch data that doesn't map cleanly to a single entity.

A joined query. An aggregate function result. A response that pulls from three tables and returns something none of your domain types actually represent. The temptation at that point is to reach for the repository anyway and invent a new type to hold the result:

type OrderWithTotal struct {
    Order
 Total float64