umstellung auf Service und Repository Verwendung - WIP
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
func NewDB(dsn string) (*gorm.DB, error) {
|
||||
// Configure GORM with custom settings
|
||||
// The logger helps with debugging SQL queries during development
|
||||
return gorm.Open(postgres.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
})
|
||||
// if err != nil {
|
||||
// log.Fatal("Failed to connect to database:", err)
|
||||
// }
|
||||
|
||||
// // Get the underlying SQL database connection for pool configuration
|
||||
// sqlDB, err := db.DB()
|
||||
// if err != nil {
|
||||
// log.Fatal("Failed to get database instance:", err)
|
||||
// }
|
||||
|
||||
// // Configure connection pool settings
|
||||
// // MaxIdleConns: number of connections kept open when idle
|
||||
// sqlDB.SetMaxIdleConns(10)
|
||||
// // MaxOpenConns: maximum total connections to the database
|
||||
// sqlDB.SetMaxOpenConns(100)
|
||||
// // ConnMaxLifetime: how long a connection can be reused
|
||||
// sqlDB.SetConnMaxLifetime(time.Hour)
|
||||
|
||||
// slog.Info("Database connected successfully")
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user