From 9d43813c88b2b1ff8bae099ea0f9d5370db838a1 Mon Sep 17 00:00:00 2001 From: iChemy Date: Fri, 19 Jan 2024 12:50:43 +0900 Subject: [PATCH 1/3] :bug: fix bug in SyncUsers --- infra/db/user.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/infra/db/user.go b/infra/db/user.go index d7b16368..97e2c585 100644 --- a/infra/db/user.go +++ b/infra/db/user.go @@ -46,7 +46,9 @@ func (repo *GormRepository) SyncUsers(users []*User) error { exist = true if u.State != eu.State { eu.State = u.State - _, err := saveUser(tx, eu) + _, err := saveUser(tx.Session(&gorm.Session{ + DisableNestedTransaction: true, + }), eu) if err != nil { return err } @@ -56,7 +58,9 @@ func (repo *GormRepository) SyncUsers(users []*User) error { } if !exist { - _, err := saveUser(tx, u) + _, err := saveUser(tx.Session(&gorm.Session{ + DisableNestedTransaction: true, + }), u) if err != nil { return err } From f60801a79ccc783f9bda8e6d7cee90e15a2f9198 Mon Sep 17 00:00:00 2001 From: iChemy Date: Fri, 16 Feb 2024 23:15:45 +0900 Subject: [PATCH 2/3] override SavePointer func --- infra/db/db.go | 19 +++++++++++++++++++ infra/db/user.go | 8 ++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/infra/db/db.go b/infra/db/db.go index 97b1ee75..1d41d839 100644 --- a/infra/db/db.go +++ b/infra/db/db.go @@ -86,3 +86,22 @@ func (d dialector) Translate(err error) error { return defaultErrorHandling(err) } + +func (d dialector) SavePoint(tx *gorm.DB, name string) error { + var err error = nil + if savePointer, ok := d.Dialector.(gorm.SavePointerDialectorInterface); ok { + err = savePointer.SavePoint(tx, name) + } else { + err = gorm.ErrUnsupportedDriver + } + return defaultErrorHandling(err) +} +func (d dialector) RollbackTo(tx *gorm.DB, name string) error { + var err error = nil + if savePointer, ok := d.Dialector.(gorm.SavePointerDialectorInterface); ok { + err = savePointer.RollbackTo(tx, name) + } else { + err = gorm.ErrUnsupportedDriver + } + return defaultErrorHandling(err) +} diff --git a/infra/db/user.go b/infra/db/user.go index 97e2c585..d7b16368 100644 --- a/infra/db/user.go +++ b/infra/db/user.go @@ -46,9 +46,7 @@ func (repo *GormRepository) SyncUsers(users []*User) error { exist = true if u.State != eu.State { eu.State = u.State - _, err := saveUser(tx.Session(&gorm.Session{ - DisableNestedTransaction: true, - }), eu) + _, err := saveUser(tx, eu) if err != nil { return err } @@ -58,9 +56,7 @@ func (repo *GormRepository) SyncUsers(users []*User) error { } if !exist { - _, err := saveUser(tx.Session(&gorm.Session{ - DisableNestedTransaction: true, - }), u) + _, err := saveUser(tx, u) if err != nil { return err } From 39a9cfe23fc6dd768a050d8a06a1eecda2e09205 Mon Sep 17 00:00:00 2001 From: iChemy Date: Sat, 17 Feb 2024 13:08:46 +0900 Subject: [PATCH 3/3] :wastebasket:del override func and explicit dialector has SavePointerDialectorInterface --- infra/db/db.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/infra/db/db.go b/infra/db/db.go index 1d41d839..d26f565f 100644 --- a/infra/db/db.go +++ b/infra/db/db.go @@ -71,6 +71,7 @@ func (repo *GormRepository) Setup(host, user, password, database, port, key, log // dialector with custom error handling type dialector struct { gorm.Dialector + gorm.SavePointerDialectorInterface } var ( @@ -86,22 +87,3 @@ func (d dialector) Translate(err error) error { return defaultErrorHandling(err) } - -func (d dialector) SavePoint(tx *gorm.DB, name string) error { - var err error = nil - if savePointer, ok := d.Dialector.(gorm.SavePointerDialectorInterface); ok { - err = savePointer.SavePoint(tx, name) - } else { - err = gorm.ErrUnsupportedDriver - } - return defaultErrorHandling(err) -} -func (d dialector) RollbackTo(tx *gorm.DB, name string) error { - var err error = nil - if savePointer, ok := d.Dialector.(gorm.SavePointerDialectorInterface); ok { - err = savePointer.RollbackTo(tx, name) - } else { - err = gorm.ErrUnsupportedDriver - } - return defaultErrorHandling(err) -}