Skip to content
Prev Previous commit
Next Next commit
Add interface do DB driver to repository
This abstraction is needed to add transactional cleanup in the future.
  • Loading branch information
xorcare committed Jul 1, 2024
commit df7598263c58aaf1413b132c8be16d214c49888c
9 changes: 7 additions & 2 deletions user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import (
"github.com/google/uuid"
)

func NewUserRepository(db *sql.DB) *UserRepository {
type DB interface {
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

func NewUserRepository(db DB) *UserRepository {
return &UserRepository{db: db}
}

type UserRepository struct {
db *sql.DB
db DB
}

func (r *UserRepository) ReadUser(ctx context.Context, userID uuid.UUID) (User, error) {
Expand Down