Sorry, forgot to add some details in the question:
Ex of repository:
type CoreUserRepository struct {
db *sqlx.DB
}
func NewCoreUserRepository(db *sqlx.DB) *CoreUserRepository {
return &CoreUserRepository{db: db}
}
func (repo *CoreUserRepository) Exists(idTenant int64, idUser int64) *int64 {
query := "SELECT id FROM core.users WHERE id_tenant=$1 AND id=$2;"
var id int64
err := repo.db.QueryRowx(query, idTenant, idUser).Scan(&id)
if err != nil {
log.Println("[CORE USERS - REPO] Could not find user: ", err)
return nil
}
return &id
}
I'm also thinking in creating Request Containers Dependency Injection for my Unit of Work. Each request creates a new container that's injects the necessary repos, usecases AND the request context. I create the UW, pass it to the context and inject the context in the usecases and repositories. With this, I'd not have the problem of having a "global transaction" in my whole application when declaring a Unit Of Work. You think that's too much? Sorry, first time with an application of this size/complexity ;-;