43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"brunel/domain"
|
||
|
"log"
|
||
|
"os"
|
||
|
"time"
|
||
|
|
||
|
"gorm.io/driver/sqlite"
|
||
|
"gorm.io/gorm"
|
||
|
"gorm.io/gorm/logger"
|
||
|
)
|
||
|
|
||
|
func New() (*gorm.DB, error) {
|
||
|
newLogger := logger.New(
|
||
|
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
|
||
|
logger.Config{
|
||
|
SlowThreshold: time.Second, // Slow SQL threshold
|
||
|
LogLevel: logger.Silent, // Log level
|
||
|
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||
|
ParameterizedQueries: true, // Don't include params in the SQL log
|
||
|
Colorful: true, // Disable color
|
||
|
},
|
||
|
)
|
||
|
|
||
|
db, err := gorm.Open(sqlite.Open("pikabldr.db"), &gorm.Config{
|
||
|
SkipDefaultTransaction: true,
|
||
|
CreateBatchSize: 1999,
|
||
|
Logger: newLogger,
|
||
|
})
|
||
|
if err != nil {
|
||
|
panic("failed to connect database")
|
||
|
}
|
||
|
|
||
|
db.AutoMigrate(&domain.User{})
|
||
|
db.AutoMigrate(&domain.Session{})
|
||
|
db.AutoMigrate(&domain.PackageInfo{})
|
||
|
db.AutoMigrate(&domain.TimeContainer{})
|
||
|
db.AutoMigrate(&domain.SourcePackageDTO{})
|
||
|
|
||
|
return db, nil
|
||
|
}
|