This commit is contained in:
Marcus Noble 2020-10-17 19:50:02 +01:00
parent 25a389d60d
commit 3f4a06f9ec

View File

@ -5,17 +5,24 @@ import (
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"gorm.io/gorm/logger"
) )
func (fs *FeedStore) getDB() *gorm.DB { func (fs *FeedStore) getDB() *gorm.DB {
db, err := gorm.Open(sqlite.Open(viper.GetString("dbPath")), &gorm.Config{}) if fs.db == nil {
db, err := gorm.Open(sqlite.Open(viper.GetString("dbPath")), &gorm.Config{
Logger: logger.Default.LogMode(logger.Error),
})
if err != nil { if err != nil {
panic("failed to connect database") panic("failed to connect database")
} }
db.AutoMigrate(&Feed{}) db.AutoMigrate(&Feed{})
db.AutoMigrate(&Item{}) db.AutoMigrate(&Item{})
return db fs.db = db
}
return fs.db
} }
func (fs *FeedStore) GetFeed(id string) *Feed { func (fs *FeedStore) GetFeed(id string) *Feed {