35 lines
606 B
Go
35 lines
606 B
Go
package main
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type favoriteRow struct {
|
|
ID string `gorm:"primaryKey"`
|
|
Favorites string
|
|
}
|
|
|
|
func (favoriteRow) TableName() string {
|
|
return "signalerr_favorites"
|
|
}
|
|
|
|
func migrateFavorites(db *gorm.DB) error {
|
|
return db.AutoMigrate(&favoriteRow{})
|
|
}
|
|
|
|
func saveFavorites(db *gorm.DB, favorites string) error {
|
|
return db.Save(&favoriteRow{
|
|
ID: "favorites",
|
|
Favorites: favorites,
|
|
}).Error
|
|
}
|
|
|
|
func loadFavorites(db *gorm.DB) string {
|
|
var row favoriteRow
|
|
err := db.First(&row, "id = ?", "favorites").Error
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return row.Favorites
|
|
}
|