1
Fork 0
photoview/api/graphql/models/site_info.go

34 lines
707 B
Go
Raw Normal View History

2020-02-05 16:49:51 +01:00
package models
import (
"github.com/pkg/errors"
"gorm.io/gorm"
2020-02-05 16:49:51 +01:00
)
2020-11-23 19:59:01 +01:00
type SiteInfo struct {
InitialSetup bool `gorm:"not null"`
PeriodicScanInterval int `gorm:"not null"`
ConcurrentWorkers int `gorm:"not null"`
}
func (SiteInfo) TableName() string {
return "site_info"
2020-11-23 19:59:01 +01:00
}
// GetSiteInfo gets the site info row from the database, and creates it if it does not exist
func GetSiteInfo(db *gorm.DB) (*SiteInfo, error) {
var siteInfo SiteInfo
2020-02-05 16:49:51 +01:00
2020-11-23 19:59:01 +01:00
err := db.FirstOrCreate(&siteInfo, SiteInfo{
InitialSetup: true,
PeriodicScanInterval: 0,
ConcurrentWorkers: 3,
2020-11-23 19:59:01 +01:00
}).Error
if err != nil {
return nil, errors.Wrap(err, "get site info from database")
2020-02-05 16:49:51 +01:00
}
return &siteInfo, nil
2020-02-05 16:49:51 +01:00
}