go-clean-architecture icon indicating copy to clipboard operation
go-clean-architecture copied to clipboard

model depends on external package

Open sinkevichmm opened this issue 2 years ago • 3 comments

Hello! Why does your model have a dependency like "gorm.io/gorm". you will be forced to change the model if:

  1. the database provider will change (for example, from gorm to gopg)
  2. database type will change (mysql to mongodb) I think a method like BeforeCreate should be inside the repo in an implementation specific internal structure.

sinkevichmm avatar Apr 12 '22 14:04 sinkevichmm

Because gorm.io/gorm is orm database and i use gorm orm for my application for interaction with database, beforeCreate is method from gorm this is hooks, check gorm documentation for more information about hooks, maybe next time, i will change gorm to gopg.

restuwahyu13 avatar Apr 12 '22 17:04 restuwahyu13

Untitled Diagram drawio

Of course i understand for what beforeCreate) In this case ModelStudent or ModelAuth is a business entity and "gorm.io/gorm" is a detail subject to change. Now you model depends on the detail. Do you agree?

sinkevichmm avatar Apr 13 '22 03:04 sinkevichmm

yes correct

restuwahyu13 avatar Jun 26 '22 05:06 restuwahyu13