blueddit/backend/db/db.go

19 lines
316 B
Go
Raw Normal View History

package db
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"blue-backend/models"
)
var DB *gorm.DB
func InitDB() {
var err error
DB, err = gorm.Open(sqlite.Open("blueddit.db"), &gorm.Config{})
if err != nil {
panic("Failed to connect to database!")
}
DB.AutoMigrate(&models.Post{}, &models.Comment{})
}