.機能追加、DBバグ修正

This commit is contained in:
2026-01-05 11:27:37 +09:00
parent 7d3da1bf2e
commit b2fbb472df
19 changed files with 1619 additions and 56 deletions

View File

@@ -2,6 +2,7 @@ package database
import (
"fmt"
"time"
"homework-manager/internal/config"
"homework-manager/internal/models"
@@ -61,6 +62,21 @@ func Connect(dbConfig config.DatabaseConfig, debug bool) error {
return err
}
// Set connection pool settings
sqlDB, err := db.DB()
if err != nil {
return err
}
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
sqlDB.SetMaxIdleConns(10)
// SetMaxOpenConns sets the maximum number of open connections to the database.
sqlDB.SetMaxOpenConns(100)
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
sqlDB.SetConnMaxLifetime(time.Hour)
DB = db
return nil
}
@@ -70,10 +86,10 @@ func Migrate() error {
&models.User{},
&models.Assignment{},
&models.APIKey{},
&models.UserNotificationSettings{},
)
}
func GetDB() *gorm.DB {
return DB
}