1
0
mirror of https://github.com/xorcare/testing-go-code-with-postgres.git synced 2025-06-30 23:23:40 +02:00

Add interface do DB driver to repository

This abstraction is needed to add transactional cleanup in the future.
This commit is contained in:
Vasiliy Vasilyuk
2024-02-17 16:39:34 +03:00
parent 912e9c9ab0
commit 83b2f61e41

View File

@ -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) {