mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-28 18:21:17 +00:00
33 lines
667 B
Go
33 lines
667 B
Go
package internal
|
|
|
|
import (
|
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/logger"
|
|
)
|
|
|
|
//go:generate just _generate-gorm
|
|
func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) {
|
|
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{
|
|
Logger: logger.Default.LogMode(logger.Info),
|
|
})
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
err = db.AutoMigrate(
|
|
models.Monitor{},
|
|
models.WorkerGroup{},
|
|
models.MonitorHistory{},
|
|
models.OAuth2State{},
|
|
)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
q := query.Use(db)
|
|
|
|
return db, q, nil
|
|
}
|