19 lines
316 B
Go
19 lines
316 B
Go
|
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{})
|
||
|
}
|