github.com/ars0915/glossika-exercise@v0.0.0-20240904180321-a5617a00d892/repo/db/init.go (about) 1 package db 2 3 import ( 4 "gorm.io/gorm" 5 6 "github.com/ars0915/glossika-exercise/repo" 7 ) 8 9 // New func implements the storage interface for app 10 func New(db *gorm.DB) *AppRepo { 11 return &AppRepo{ 12 db: db, 13 } 14 } 15 16 // AppRepo is interface structure 17 type AppRepo struct { 18 db *gorm.DB 19 } 20 21 // Begin begin a transaction 22 func (s *AppRepo) Begin() repo.App { 23 return &AppRepo{ 24 db: s.db.Begin(), 25 } 26 } 27 28 // Commit commit a transaction 29 func (s *AppRepo) Commit() error { 30 return s.db.Commit().Error 31 } 32 33 // Rollback rollback a transaction 34 func (s *AppRepo) Rollback() error { 35 return s.db.Rollback().Error 36 } 37 38 // Debug Debug log 39 func (s *AppRepo) Debug() { 40 s.db = s.db.Debug() 41 } 42 43 // type jsonLogger struct{} 44 45 // func (*jsonLogger) Print(values ...interface{}) { 46 // if len(values) > 1 { 47 // logrus.WithFields(log.Fields{"type": values[0], "full": values[0:]}).Info("GORM Log") 48 // } 49 // }