Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSNをDSNconfigを使用する形に変更 #2465

Merged
merged 7 commits into from
Jul 22, 2024
Merged

DSNをDSNconfigを使用する形に変更 #2465

merged 7 commits into from
Jul 22, 2024

Conversation

24take
Copy link
Contributor

@24take 24take commented Jun 25, 2024

resolve: #1873

@ikura-hamu ikura-hamu marked this pull request as draft June 25, 2024 07:43
@24take 24take marked this pull request as ready for review June 25, 2024 08:19
@ikura-hamu ikura-hamu requested a review from pikachu0310 June 25, 2024 10:11
Copy link
Contributor

@pikachu0310 pikachu0310 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビュー遅くてごめんなさい!
貢献ありがとうございます!かなり良く書けていると思います!
一箇所だけ気になった点があるので、確認お願いします~!

Comment on lines 69 to 71
config.DBName = fmt.Sprintf("%s%s", dbPrefix, key)
engine, err := gorm.Open(mysql.New(mysql.Config{
DSN: fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", user, pass, host, port, fmt.Sprintf("%s%s", dbPrefix, key)),
DSNConfig: config,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

結構細かいですが、

この実装は config.DBName = fmt.Sprintf("%s%s", dbPrefix, key)config 構造体の元の値を直接変更してるけど、以下の様に元の値を直接変更するのではなくコピーしてから変更した方が、コードの意図が明確になって、さらに他の部分への影響を防ぐことでメンテナンス上でバグが起きにくくなりそうです!

Suggested change
config.DBName = fmt.Sprintf("%s%s", dbPrefix, key)
engine, err := gorm.Open(mysql.New(mysql.Config{
DSN: fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", user, pass, host, port, fmt.Sprintf("%s%s", dbPrefix, key)),
DSNConfig: config,
dbConfig := *config
dbConfig.DBName = fmt.Sprintf("%s%s", dbPrefix, key)
engine, err := gorm.Open(mysql.New(mysql.Config{
DSNConfig: &dbConfig,

Comment on lines 67 to 71
config.DBName = fmt.Sprintf("%s%s", dbPrefix, key)

// テスト用データベース接続
engine, err := gorm.Open(mysql.New(mysql.Config{
DSN: fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", user, pass, host, port, fmt.Sprintf("%s%s", dbPrefix, key)),
DSNConfig: config,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ココも同様

Comment on lines 79 to 84
config.DBName = fmt.Sprintf("%s%s", dbPrefix, key)
l := zap.NewNop()

// テスト用データベース接続
engine, err := gorm.Open(mysql.New(mysql.Config{
DSN: fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", user, pass, host, port, fmt.Sprintf("%s%s", dbPrefix, key)),
DSNConfig: config,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ココも同様

Copy link
Contributor

@pikachu0310 pikachu0310 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビュー遅くてごめんなさい!LGTM;良さそうです!
お疲れさまでした~!

@pikachu0310 pikachu0310 merged commit d33dcfe into master Jul 22, 2024
6 checks passed
@pikachu0310 pikachu0310 deleted the issue1873 branch July 22, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DBのDSN生成をライブラリに任せる
2 participants