database

package
v0.0.0-...-9285160 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *gorm.DB
)

Functions

func CheckError

func CheckError(err error)

CheckError inspects a GORM error for SQLite corruption or a closed database connection. Delegates to the watchdog package for auto-repair.

func DBPath

func DBPath() string

DBPath returns the database file path used at init.

func Get

func Get() *gorm.DB

Get returns the current database connection. Use this instead of storing a *gorm.DB reference so that watchdog reconnects propagate automatically.

func Init

func Init(path string)

func Reinit

func Reinit() error

Reinit closes the current connection and reopens the database. Called after restoring from backup to pick up the new DB file.

func RestoreFromBackup

func RestoreFromBackup() error

RestoreFromBackup is the package-level function called by the watchdog.

func StartBackups

func StartBackups(ctx context.Context, dataDir string, interval time.Duration)

StartBackups initialises and starts the background backup manager.

Types

type BackupManager

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

BackupManager performs two tiers of online backups using SQLite's Backup API:

  1. Rotating snapshots: frequent (default 5m), 3 slots — for crash/corruption recovery.
  2. Daily archives: one per day, kept for 30 days — for real data-loss recovery.

func (*BackupManager) Restore

func (bm *BackupManager) Restore() error

Restore finds the newest valid backup across both tiers and replaces the main database.

func (*BackupManager) Start

func (bm *BackupManager) Start(ctx context.Context)

Start runs the periodic backup loop.

Jump to

Keyboard shortcuts

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