Raw SQL Queries in Go LIKE a 10x Engineer! - Repository Pattern Example

preview_player
Показать описание
I'm sure as a Go engineer you've had to work with raw SQL queries in Go before! Maintaining raw SQL queries can be a pain. So in this video, I discuss a pattern I've been following recently to help manage SQL queries within my repository implementations. It's a simple concept but nonetheless, I thought it was worth a video as I've seen some pretty unmaintable code dealing with this in the past. This is also a pretty good example of the repository pattern in Golang.

Рекомендации по теме
Комментарии
Автор

Your teaching style is good keep up the good work.

katungiyassin
Автор

You can get type-safe raw sql if you're using jetbrains IDEs with autocomplete and suggestions because all the ides are well-integrated with databases & its own dbms. They can compared your created tables in the db with your raw sql and highlight any errors in the raw sql.

ArcticPrimal
Автор

Using testcontainers (or similar tool) is a game changer. Please don't make integration tests with in-memory dbs if you are not using one

jpcairesf
Автор

Nice vid. I need to know your color theme tho, looks so fitting for golang (might sound strange, but i really think that)

newpersxn
Автор

Thanks for the amazing explanation. I'm currently learning Go. One question though. Isn't using a transaction for everything a bit expensive?

Cyber_Lanka
Автор

How do you setup the database in the tests? and how do you handle migrations?

eedvfkr
Автор

Awesome video but volume of sound is low. I had to put volume to max on my laptop to hear it clearly.

anonymouse
Автор

Why do you prefer using raw SQL as opposed to using an ORM like GORM? People have various opinions about this, just want to hear you on this one…

YvanFlorian
Автор

For the integration tests what I'm doing is to spin up a new test schema that is a clone of the public schema and execute my migration files.

Then while testing I temporarily set the search_path of the database to the test schema.

Finally, if the test passed I remove the test schema, this has the added benefit that if a test fails I can keep the test schema and inspect it manually to see on which table structure or data the test failed on.

geoblk