29 lines
664 B
Go
29 lines
664 B
Go
|
|
package db
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"app/shelfly/internal/models"
|
||
|
|
"gorm.io/driver/sqlite"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
func InitDB()*gorm.DB {
|
||
|
|
|
||
|
|
dbName:="shelfly_db.db"
|
||
|
|
// Ouvre une connexion à la base de données
|
||
|
|
db, err := gorm.Open(sqlite.Open(dbName), &gorm.Config{})
|
||
|
|
if err != nil {
|
||
|
|
panic("failed to connect database")
|
||
|
|
}
|
||
|
|
|
||
|
|
// Migrate the schema
|
||
|
|
db.AutoMigrate(&models.User{},&models.Files{},&models.LibrarySection{},&models.MediaItem{},&models.MediaPart{},&models.MetadataItem{},&models.SectionLocation{},&models.Tag{},&models.Tagging{},&models.PathDownload{})
|
||
|
|
|
||
|
|
fmt.Println("Connexion réussie à MySQL !")
|
||
|
|
fmt.Println("Auto migration completed")
|
||
|
|
return db
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|