From 89564e363b10bf10d146a6ada9a7ea215aeae76c Mon Sep 17 00:00:00 2001 From: iChemy Date: Mon, 15 Jul 2024 20:59:30 +0900 Subject: [PATCH] :file: delete dialector --- infra/db/db.go | 58 +++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/infra/db/db.go b/infra/db/db.go index d26f565f..b5c6a868 100644 --- a/infra/db/db.go +++ b/infra/db/db.go @@ -37,28 +37,24 @@ func (repo *GormRepository) Setup(host, user, password, database, port, key, log } tokenKey = []byte(key) - d := dialector{ - Dialector: mysql.New(mysql.Config{ - DSNConfig: &gomysql.Config{ - User: user, - Passwd: password, - Net: "tcp", - Addr: host + ":" + port, - DBName: database, - Loc: loc, - AllowNativePasswords: true, - ParseTime: true, - }, - DefaultStringSize: 256, // default size for string fields - DisableDatetimePrecision: true, // disable datetime precision, which not supported before MySQL 5.6 - DontSupportRenameIndex: true, // drop & create when rename index, rename index not supported before MySQL 5.7, MariaDB - DontSupportRenameColumn: false, // `change` when rename column, rename column not supported before MySQL 8, MariaDB - SkipInitializeWithVersion: false, // auto configure based on currently MySQL version - }), - } - var err error - repo.db, err = gorm.Open(d, &gorm.Config{ + repo.db, err = gorm.Open(mysql.New(mysql.Config{ + DSNConfig: &gomysql.Config{ + User: user, + Passwd: password, + Net: "tcp", + Addr: host + ":" + port, + DBName: database, + Loc: loc, + AllowNativePasswords: true, + ParseTime: true, + }, + DefaultStringSize: 256, // default size for string fields + DisableDatetimePrecision: true, // disable datetime precision, which not supported before MySQL 5.6 + DontSupportRenameIndex: true, // drop & create when rename index, rename index not supported before MySQL 5.7, MariaDB + DontSupportRenameColumn: false, // `change` when rename column, rename column not supported before MySQL 8, MariaDB + SkipInitializeWithVersion: false, // auto configure based on currently MySQL version + }), &gorm.Config{ Logger: logger.Default.LogMode(loglevel), }) if err != nil { @@ -67,23 +63,3 @@ func (repo *GormRepository) Setup(host, user, password, database, port, key, log return migration.Migrate(repo.db, tables) } - -// dialector with custom error handling -type dialector struct { - gorm.Dialector - gorm.SavePointerDialectorInterface -} - -var ( - _ gorm.Dialector = (*dialector)(nil) - _ gorm.ErrorTranslator = (*dialector)(nil) -) - -// override Translate(err error) error -func (d dialector) Translate(err error) error { - if translater, ok := d.Dialector.(gorm.ErrorTranslator); ok { - err = translater.Translate(err) - } - - return defaultErrorHandling(err) -}