2024-02-11 10:56:21 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2024-02-11 19:28:00 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
2024-02-11 10:56:21 +00:00
|
|
|
"github.com/glebarez/sqlite"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
2024-02-11 11:57:57 +00:00
|
|
|
//go:generate just _generate-gorm
|
2024-02-11 19:28:00 +00:00
|
|
|
func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) {
|
|
|
|
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
2024-02-11 10:56:21 +00:00
|
|
|
if err != nil {
|
2024-02-11 19:28:00 +00:00
|
|
|
return nil, nil, err
|
2024-02-11 10:56:21 +00:00
|
|
|
}
|
|
|
|
|
2024-02-11 19:28:00 +00:00
|
|
|
db.AutoMigrate(&models.Healthcheck{})
|
|
|
|
|
|
|
|
q := query.Use(db)
|
|
|
|
|
|
|
|
return db, q, nil
|
2024-02-11 10:56:21 +00:00
|
|
|
}
|