db_tools

package
v0.0.0-...-b18537c Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 9 Imported by: 0

README

db-tools

Contains a most basic database tools:

  • Backup API
  • Backup Manager

Documentation

Index

Constants

View Source
const (
	DAY_INTERVAL  = 24 * time.Hour
	WEEK_INTERVAL = DAY_INTERVAL * 7
)
View Source
const BackupIDTimeFormat = "20060102T150405"
View Source
const DateTimeStringFormat = "2006-01-02 15:04:05.000000"

Variables

This section is empty.

Functions

func FilterTimes

func FilterTimes(items []time.Time, filter func(t time.Time) bool) (filtered, other []time.Time)

func TimesAt

func TimesAt(items []time.Time, at time.Time) (filtered, other []time.Time)

func ToDay

func ToDay(t time.Time) time.Time

func ToMonth

func ToMonth(t time.Time) time.Time

func ToWeek

func ToWeek(t time.Time) time.Time

func ToYear

func ToYear(t time.Time) time.Time

Types

type ArchivedBackuper

type ArchivedBackuper interface {
	Backuper
	OpenArchive() (io.ReadCloser, error)
}

type Backup

type Backup struct {
	OpenFunc   func() (io.ReadCloser, error) `json:"-" gorm:"-"`
	DetailFunc func(ctx context.Context) string
	CreatedAt  time.Time
	DbName     string
	Message    string
	Size       int64
	Auto       bool
}

func (*Backup) DetailString

func (b *Backup) DetailString(ctx context.Context) string

func (*Backup) GetCreatedAt

func (b *Backup) GetCreatedAt() time.Time

func (*Backup) GetDbName

func (b *Backup) GetDbName() string

func (*Backup) GetID

func (b *Backup) GetID() (id BackupID)

func (*Backup) GetMessage

func (b *Backup) GetMessage() string

func (*Backup) GetSize

func (b *Backup) GetSize() int64

func (*Backup) IsAuto

func (b *Backup) IsAuto() bool

func (*Backup) Open

func (b *Backup) Open() (io.ReadCloser, error)

type BackupController

type BackupController interface {
	CurrentName(ctx context.Context) (name string, err error)
	Create(auto bool, message string) (bkp Backuper, err error)
	Remove(id BackupID) error
	RemoveOlder(auto bool, p *Persistence) (removed []Backuper, err error)
	Get(id BackupID) (Backuper, error)
	Download(aw http.ResponseWriter, r *http.Request, id BackupID) (err error)
	List(auto bool, cb func(bkp Backuper) error, filter ListFilter) (err error)
	Count(auto bool, filter ListFilter) (count int, err error)
}

type BackupID

type BackupID struct {
	Auto      bool
	DbName    string
	CreatedAt time.Time
}

func (BackupID) IsValid

func (id BackupID) IsValid() bool

func (*BackupID) Parse

func (id *BackupID) Parse(v string) (err error)

func (BackupID) String

func (id BackupID) String() string

type Backuper

type Backuper interface {
	Open() (io.ReadCloser, error)
	GetCreatedAt() time.Time
	GetID() BackupID
	GetDbName() string
	GetMessage() string
	GetSize() int64
	IsAuto() bool
	DetailString(ctx context.Context) string
}

type BackupsMapper

type BackupsMapper struct {
	// contains filtered or unexported fields
}

func Mapper

func Mapper(backups []Backuper) *BackupsMapper

func (*BackupsMapper) Keys

func (b *BackupsMapper) Keys() []time.Time

func (*BackupsMapper) Map

func (b *BackupsMapper) Map() map[time.Time]Backuper

type DateTimeFilter

type DateTimeFilter interface {
	Valid(t time.Time) bool
}

type DateTimeRangeFilter

type DateTimeRangeFilter [2]time.Time

func (DateTimeRangeFilter) MarshalJSON

func (r DateTimeRangeFilter) MarshalJSON() ([]byte, error)

func (DateTimeRangeFilter) Parse

func (v DateTimeRangeFilter) Parse(from, to string) (err error)

func (DateTimeRangeFilter) Valid

func (r DateTimeRangeFilter) Valid(t time.Time) bool

type DateTimeValueFilter

type DateTimeValueFilter time.Time

func (DateTimeValueFilter) MarshalJSON

func (r DateTimeValueFilter) MarshalJSON() ([]byte, error)

func (*DateTimeValueFilter) Parse

func (v *DateTimeValueFilter) Parse(s string) (err error)

func (DateTimeValueFilter) String

func (v DateTimeValueFilter) String() string

func (DateTimeValueFilter) Valid

func (v DateTimeValueFilter) Valid(t time.Time) bool

type Group

type Group struct {
	Key   time.Time
	Items []time.Time
}

func GroupBy

func GroupBy(group func(t time.Time) time.Time, items []time.Time) (r []*Group)

func GroupByWithFilter

func GroupByWithFilter(items []time.Time, end time.Time, key func(t time.Time) time.Time) (r []*Group, other []time.Time, end_ time.Time)

func (*Group) Add

func (g *Group) Add(item ...time.Time)

func (*Group) MustLast

func (g *Group) MustLast(rm func(t []time.Time))

type Groups

type Groups []*Group

func (Groups) MustLast

func (s Groups) MustLast(rm func(t []time.Time))

type IntervalGrouper

type IntervalGrouper struct {
	Days   Groups
	Weeks  Groups
	Months Groups
	Years  Groups
}

func (*IntervalGrouper) MustLast

func (i *IntervalGrouper) MustLast(rm func(t []time.Time))

type ListFilter

type ListFilter interface {
	Year() ListFilterIntValuer
	Month() ListFilterIntValuer
	Day() ListFilterIntValuer
	Hour() ListFilterIntValuer
	DateTime() DateTimeFilter
}

type ListFilterBuilder

type ListFilterBuilder struct {
	// contains filtered or unexported fields
}

func NewListFilter

func NewListFilter() *ListFilterBuilder

func (*ListFilterBuilder) DateTime

func (b *ListFilterBuilder) DateTime() DateTimeFilter

func (*ListFilterBuilder) Day

func (*ListFilterBuilder) Hour

func (*ListFilterBuilder) MarshalJSON

func (b *ListFilterBuilder) MarshalJSON() ([]byte, error)

func (*ListFilterBuilder) Month

func (*ListFilterBuilder) WithDateTime

func (*ListFilterBuilder) WithDay

func (*ListFilterBuilder) WithHour

func (*ListFilterBuilder) WithMonth

func (*ListFilterBuilder) WithYear

func (*ListFilterBuilder) Year

type ListFilterIntValue

type ListFilterIntValue int

func (ListFilterIntValue) Valid

func (i ListFilterIntValue) Valid(v int) bool

type ListFilterIntValueRange

type ListFilterIntValueRange [2]int

func (ListFilterIntValueRange) FromValue

func (r ListFilterIntValueRange) FromValue() int

func (ListFilterIntValueRange) ToValue

func (r ListFilterIntValueRange) ToValue() int

func (ListFilterIntValueRange) Valid

func (r ListFilterIntValueRange) Valid(v int) bool

type ListFilterIntValueRanger

type ListFilterIntValueRanger interface {
	FromValue() int
	ToValue() int
}

type ListFilterIntValuer

type ListFilterIntValuer interface {
	Valid(v int) bool
}

type Persistence

type Persistence struct {
	Enabled bool             `json:"Enabled,omitempty"`
	Years   int              `json:"Years,omitempty"`
	Months  int              `json:"Months,omitempty"`
	Weeks   int              `json:"Weeks,omitempty"`
	Days    int              `json:"Days,omitempty"`
	Other   PersistenceOther `json:"Other,omitempty"`
}

func (*Persistence) Group

func (p *Persistence) Group(items []time.Time) (g *IntervalGrouper, other []time.Time)

Group groups sorted items

func (*Persistence) IsZero

func (p *Persistence) IsZero() bool

type PersistenceOther

type PersistenceOther uint8
const (
	PersistenceOtherDays PersistenceOther = iota + 1
	PersistenceOtherWeeks
	PersistenceOtherMonths
	PersistenceOtherYears
)

func (*PersistenceOther) Parse

func (o *PersistenceOther) Parse(v string) (err error)

func (PersistenceOther) String

func (o PersistenceOther) String() string

Jump to

Keyboard shortcuts

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