chore: Disable low-level database error messages
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
0c81963131
commit
e7c18d048e
1 changed files with 9 additions and 4 deletions
13
db.go
13
db.go
|
@ -5,21 +5,26 @@ import (
|
|||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
var gconfig = &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
}
|
||||
|
||||
// NewDatabaseFromConfig creates a database object from configuration structure
|
||||
func NewDatabaseFromConfig(config DatabaseConfig) (*gorm.DB, error) {
|
||||
switch config.Type {
|
||||
case "postgres":
|
||||
return gorm.Open(postgres.New(postgres.Config{DSN: config.DSN}), &gorm.Config{})
|
||||
return gorm.Open(postgres.New(postgres.Config{DSN: config.DSN}), gconfig)
|
||||
case "mysql":
|
||||
return gorm.Open(mysql.New(mysql.Config{DSN: config.DSN}), &gorm.Config{})
|
||||
return gorm.Open(mysql.New(mysql.Config{DSN: config.DSN}), gconfig)
|
||||
default:
|
||||
return gorm.Open(sqlite.Open(config.DSN), &gorm.Config{})
|
||||
return gorm.Open(sqlite.Open(config.DSN), gconfig)
|
||||
}
|
||||
}
|
||||
|
||||
// NewDatabaseFromFile creates a database object from path to file (passed as argument)
|
||||
func NewDatabaseFromFile(path string) (*gorm.DB, error) {
|
||||
return gorm.Open(sqlite.Open(path), &gorm.Config{})
|
||||
return gorm.Open(sqlite.Open(path), gconfig)
|
||||
}
|
||||
|
|
Reference in a new issue