Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f4aa95f

Browse files
committedJul 1, 2024
Add interface do DB driver to repository
This abstraction is needed to add transactional cleanup in the future.
1 parent f583d2b commit f4aa95f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎user_repository.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ import (
1212
"github.com/google/uuid"
1313
)
1414

15-
func NewUserRepository(db *sql.DB) *UserRepository {
15+
type DB interface {
16+
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
17+
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
18+
}
19+
20+
func NewUserRepository(db DB) *UserRepository {
1621
return &UserRepository{db: db}
1722
}
1823

1924
type UserRepository struct {
20-
db *sql.DB
25+
db DB
2126
}
2227

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

0 commit comments

Comments
 (0)
Please sign in to comment.