27 lines
460 B
Go
27 lines
460 B
Go
package db
|
|
|
|
import (
|
|
"log"
|
|
|
|
"example/hello/api"
|
|
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ConnectDB initializes the database connection
|
|
func ConnectDB() *gorm.DB {
|
|
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
|
|
if err != nil {
|
|
panic("failed to connect database")
|
|
}
|
|
|
|
log.Println("Database connected successfully")
|
|
return db
|
|
}
|
|
|
|
func Migrate(db *gorm.DB) {
|
|
db.AutoMigrate(&api.Pet{})
|
|
log.Println("Database migrated successfully")
|
|
}
|