Reuse DB
This commit is contained in:
parent
25a389d60d
commit
3f4a06f9ec
@ -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 {
|
||||||
if err != nil {
|
db, err := gorm.Open(sqlite.Open(viper.GetString("dbPath")), &gorm.Config{
|
||||||
panic("failed to connect database")
|
Logger: logger.Default.LogMode(logger.Error),
|
||||||
}
|
})
|
||||||
db.AutoMigrate(&Feed{})
|
if err != nil {
|
||||||
db.AutoMigrate(&Item{})
|
panic("failed to connect database")
|
||||||
|
}
|
||||||
|
db.AutoMigrate(&Feed{})
|
||||||
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user