unified-push-xmpp/distributor/storage/store.go

39 lines
687 B
Go
Raw Normal View History

2021-09-26 05:29:33 +02:00
package storage
import (
"gorm.io/gorm"
"unifiedpush.org/go/np2p_dbus/storage"
)
func InitStorage(path string) (*Storage, error) {
st, err := storage.InitStorage(path)
db := st.DB()
if err := db.AutoMigrate(&latestID{}); err != nil {
return nil, err
}
return &Storage{Storage: st, db: st.DB()}, err
}
type Storage struct {
*storage.Storage
db *gorm.DB
}
func (d Storage) GetLatestNotif() (int64, error) {
id := latestID{}
result := d.db.First(&id)
return id.ID, result.Error
}
func (d Storage) SaveLatestNotif(time int64) error {
id := latestID{}
result := d.db.Model(&id).Where("1=1").Update("id", time)
return result.Error
}
type latestID struct {
ID int64
}