first commit

This commit is contained in:
2024-12-09 19:52:07 -05:00
commit e092b0d172
7 changed files with 214 additions and 0 deletions

25
database/database.go Normal file
View File

@@ -0,0 +1,25 @@
// database/database.go
package database
import (
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gitea.ghost.tel/knight/library/models"
)
var DB *gorm.DB
func ConnectDatabase() {
database, err := gorm.Open(sqlite.Open("books.db"), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to database:", err)
}
// Migrate the schema
database.AutoMigrate(&models.Book{})
DB = database
}