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

31 lines
603 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 {
gorm.Model
InitialSetup bool
PeriodicScanInterval int
ConcurrentWorkers int
}
// 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
}