This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
swb6-it-sec/Lab01/app/database/database.go

24 lines
435 B
Go
Raw Normal View History

2022-03-30 12:39:04 +02:00
package database
import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func migrateInitial(orm *gorm.DB) {
err := orm.AutoMigrate(&User{})
if err != nil {
fmt.Println(fmt.Errorf("failed to migrate User"))
}
}
func (db *Database) Initialize() {
orm, err := gorm.Open(sqlite.Open(db.Location), &gorm.Config{})
if err != nil {
fmt.Println(fmt.Errorf("failed to connect Database"))
}
migrateInitial(orm)
db.ORM = orm
}