db

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DenormalizeValues

func DenormalizeValues(values []string) string

func NewLogger

func NewLogger(level string) *dlogger

Types

type Database

type Database interface {
	CreateNewSubDomain(tokenHash, domainName string) (Domain, error)
	GetDomain(domain string) (Domain, error)
	PersistRecord(domainID uint, fqdn, rType string, values []string) error
	Renew(domainID uint, fqdnTypePairs []model.FQDNTypePair, version string) error
	GetDomainRecords(domainID uint) (map[model.FQDNTypePair]Record, error)
	GetDomainRecordsByFQDN(fqdn string, domainID uint) ([]Record, error)
	DeleteRecords(records []Record) error
	PurgeOldDomainsAndRecords(maxDomainAgeSeconds, maxRecordAgeSeconds int64) (int64, int64, error)
	GetYoungRecords(maxAgeSeconds int64, fqdnTypePairs map[model.FQDNTypePair]bool) (map[model.FQDNTypePair]Record, error)
}

func New

func New(ctx context.Context, engine string, dsn string, config *gorm.Config) (Database, error)

New creates a new database connection

type Domain

type Domain struct {
	gorm.Model
	UniqueSlug  string `gorm:"uniqueIndex"`
	Domain      string `gorm:"uniqueIndex"`
	TokenHash   string
	LastCheckIn time.Time
	Version     string
}

type Record

type Record struct {
	ID          uint   `gorm:"primarykey"`
	FQDN        string `gorm:"uniqueIndex:idx_record,priority:1"`
	Type        string `gorm:"uniqueIndex:idx_record,priority:2"`
	DomainID    uint
	Domain      Domain `gorm:"constraint:OnDelete:SET NULL;"`
	Values      string `gorm:"type:text"` // Intentionally denormalized because we don't want to create a values table
	CreatedAt   time.Time
	LastCheckIn time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL