package storage import ( "git.espin.casa/albert/logger" "gorm.io/driver/sqlite" "gorm.io/gorm" ) type Storage struct { db *gorm.DB log logger.LoggerAdapter } type Bulletin struct { gorm.Model Board string `json:"board"` SenderShortName string `json:"sender_short_name"` Subject string `json:"subject"` Content string `json:"content"` UniqueID string `json:"unique_id"` } type Mail struct { gorm.Model Sender string `json:"sender"` SenderShortName string `json:"sender_short_name"` Recipient string `json:"recipient"` Subject string `json:"subject"` Content string `json:"content"` UniqueID string `json:"unique_id"` } type Channel struct { gorm.Model Name string `json:"name"` Url string `json:"url"` } // ListBulletins list all bulletins in database func (s *Storage) ListBulletins() (bulletins []Bulletin, err error) { s.db. } func (s *Storage) ListMail() ([]Mail, error) { } func NewStorage(path string, log logger.LoggerAdapter) (*Storage, error) { db, err := gorm.Open(sqlite.Open(path), &gorm.Config{}) if err != nil { return nil, err } // AutoMigrate will create the tables and necessary constraints for your models err = db.AutoMigrate(&Bulletin{}, &Mail{}, &Channel{}) if err != nil { return nil, err } return &Storage{db: db, log: log}, nil } func (s *Storage) Close() error { sqlDB, err := s.db.DB() if err != nil { return err } return sqlDB.Close() }