TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The adapter pattern in Go

5 pointsby gus_leonelalmost 2 years ago

1 comment

cbarrickalmost 2 years ago
I was very surprised to see all of the negative sentiment on the other thread [1].<p>The prevailing opinion seemed to be &quot;just use a real database,&quot; specifically in the contexts of testing. As in, why test against a mock adapter when you could test against your actual DB (or sqlite), with very little concern given to the adapter pattern in and of itself.<p>But I think that sentiment misses two points:<p>1. The adapter pattern is a pleasant API from a user perspective, regardless of your approach to testing.<p>2. As far as testing goes, why not both? You should absolutely have functional&#x2F;integration tests against a real database, but pure unit tests are also useful for highly portable test environments. This is especially true in larger orgs where you can&#x27;t just ship a Dockerfile to everyone to ensure they all have a consistent dev environment.<p>There was also a concern about adapters hiding the SQL that gets run, or making more queries than is needed, which makes it difficult to debug query performance. I think this is the most valid argument against the pattern, but it&#x27;s not an insurmountable problem.<p>[1]: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=36890681">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=36890681</a>