In theory, I think it makes sense to encapsulate the database connection logic to make it more easily reusable, but as the link below argues, our modern frameworks essentially take care of this now.
Reconsidering the Repository PatternReconsidering the Repository Pattern