23 lines
435 B
Go
23 lines
435 B
Go
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
|
|
}
|