Skip to content

Commit

Permalink
fix: can now close connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed May 20, 2022
1 parent b165533 commit 01dede5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions repo/inmemory/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ func (r *Repository) Migrate(_ context.Context) error {

return nil
}

// Close closes any external connection in the repository.
func (r *Repository) Close(_ context.Context) error {
r.log.Debug("in-memory repository has no external connection to close")

return nil
}
10 changes: 10 additions & 0 deletions repo/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ func (r *Repository) Migrate(_ context.Context) error {

return nil
}

// Close closes any external connection in the repository.
func (r *Repository) Close(_ context.Context) error {
db, err := r.db.DB()
if err != nil {
return fmt.Errorf("get db instance: %w", err)
}

return db.Close()
}
1 change: 1 addition & 0 deletions repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Repository interface {
Get(context.Context, string) (*deck.Deck, error)
Save(context.Context, *deck.Deck) error
Migrate(context.Context) error
Close(ctx context.Context) error
}

// NewRepository returns a new repository.
Expand Down

0 comments on commit 01dede5

Please sign in to comment.