You've already forked testing-go-code-with-postgres
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:
@ -12,12 +12,17 @@ import (
|
|||||||
"github.com/google/uuid"
|
"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}
|
return &UserRepository{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserRepository struct {
|
type UserRepository struct {
|
||||||
db *sql.DB
|
db DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *UserRepository) ReadUser(ctx context.Context, userID uuid.UUID) (User, error) {
|
func (r *UserRepository) ReadUser(ctx context.Context, userID uuid.UUID) (User, error) {
|
||||||
|
Reference in New Issue
Block a user