Typesafe SQL queries in Golang

When writing web applications we often reach to ORMs to help us with the connection to the database layer. This is something that generally speed up the development of applications, but has a tradeoff in performance and complexity. I have worked in some very large code bases that took an expensive performance hit from the ORM. Some of the queries that were generated where interesting. Writing SQL directly is usually going to have better performance characteristics than auto-generating SQL queries based on a model. Especially as the complexity of the data grows. There are downsides with this, having to write loading and saving logic being a big time cost. It’s also important to write tests to ensure that there is no regression if there are changes in the data model. ...

February 12, 2025 · 2 min · Thomas Winsnes