github.com/lovung/GoCleanArchitecture@v0.0.0-20210302152432-50d91fd29f9f/app/internal/interface/persistence/rdbms/gormrepo/base_repository.go (about) 1 package gormrepo 2 3 import ( 4 "context" 5 6 "github.com/lovung/GoCleanArchitecture/app/internal/appctx" 7 8 "gorm.io/gorm" 9 ) 10 11 type baseRepository struct{} 12 13 // DB to get the transaction to Database from context 14 func (r *baseRepository) DB(ctx context.Context) *gorm.DB { 15 v := ctx.Value(appctx.TransactionContextKey) 16 gormDB, ok := v.(*gorm.DB) 17 if !ok { 18 panic("can not get the gorm.DB in context") 19 } 20 return gormDB 21 }