state

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathInMemory = ":memory:"
)

Variables

View Source
var (
	ErrVersionUnknown = fmt.Errorf("unknown version")
)

Functions

This section is empty.

Types

type History

type History = HistoryV1

Latest version of history schema

type HistoryV1

type HistoryV1 struct {
	DotPath   string    `gorm:"primaryKey"` // file path that is in use for system
	DttPath   string    `gorm:"not null"`   // file path that is in your dotato repository
	Mode      string    `gorm:"not null"`
	CreatedAt time.Time `gorm:"autoCreateTime"`
	UpdatedAt time.Time `gorm:"autoUpdateTime"`
}

type State

type State struct {
	DB *gorm.DB
}

func New

func New(fs billy.Filesystem, statePath string) (*State, error)

What New does:

  • Initialize db instance
  • Migrate db to latest version

func (State) Delete

func (s State) Delete(h History) error

func (State) GetAllByMode

func (s State) GetAllByMode(mode string) ([]History, error)

func (State) Tx

func (s State) Tx(fn func(tx *gorm.DB) error) error

Doc at https://gorm.io/docs/transactions.html#Transaction

func (State) TxDelete

func (s State) TxDelete(tx *gorm.DB, h History) error

func (State) TxGetAllByMode

func (s State) TxGetAllByMode(tx *gorm.DB, mode string) ([]History, error)

func (State) TxSafe

func (s State) TxSafe(fn func(tx *gorm.DB) error) error

Intercept error from fn, run tx safely and return the error

func (State) TxUpsert

func (s State) TxUpsert(tx *gorm.DB, h History) error

func (State) Upsert

func (s State) Upsert(h History) error

type Store

type Store struct {
	Key   string `gorm:"primaryKey"`
	Value string
}

Key value store

type Version

type Version string

DB schema version

const (
	KeyVersion             = "version"
	VersionUnknown Version = "unknown"
	Version1       Version = "v1"
	DBVersion      Version = Version1
)

Jump to

Keyboard shortcuts

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