first commit
This commit is contained in:
25
database/database.go
Normal file
25
database/database.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user