Creating mock objects for data repositories is a common requirement in web application development. In this article, I will show you how to use GoMock to automatically generate mocks for your interfaces and use them inside unit tests. When you have a service that depends on a repository to fetch some data, this repository will most likely be connected to a database. A typical sequence of events could look like this: Service A requests an object X from repository B ...

When using the sqlx package in Go with a Postgres database, you may come across the following error: lastinsertid is not supported by this driver postgres This error will happen when you want to access the LastInsertId() of a newly inserted entity. In this post, I will show you how to fix this error without making any changes to your database. Let’s investigate a specific scenario where this error will occur: func CreateAppointment(appointment Appointment) int { result, err := database.Db.NamedExec("INSERT ...

Bernhard Knasmüller on Software Development