gorm

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListMachines

func ListMachines(db *gorm.DB) ([]*amhist.MachineRecord, error)

ListMachines returns a list of all machines in a database. TODO

func NewDb added in v0.17.1

func NewDb(name string, debug bool) (*gorm.DB, *sql.DB, error)

NewDb returns a new SQLite DB for GORM.

Types

type Config

type Config struct {
	amhist.BaseConfig

	// amount of records to save in bulk (default: 1000)
	QueueBatch int32
	// amount of goroutines doing bulk saving (default: 10)
	SavePool int
}

type Machine

type Machine struct {
	ID uint32 `gorm:"primaryKey"`

	Times  []Time
	States []State

	MachId     string `gorm:"column:mach_id;index:mach_id"`
	StateNames datatypes.JSON
	Schema     datatypes.JSON

	// first time the machine has been tracked
	FirstTracking time.Time
	// last time a tracking of this machine has started
	LastTracking time.Time
	// last time a sync has been performed
	LastSync time.Time

	// current machine start tick
	MachTick uint32
	// current (total) machine time
	// TODO optimize: collect in a separate query
	MTime datatypes.JSON
	// sum of the current machine time
	MTimeSum uint64
	// next ID for time records
	NextId uint64
	// contains filtered or unexported fields
}

Machine is a SQL version of amhist.MachineRecord.

func GetMachine

func GetMachine(db *gorm.DB, id string, inclStates bool) (*Machine, error)

GetMachine returns a machine record for a given machine id.

type MatcherFn

type MatcherFn func(now *am.TimeIndex, query *gorm.DB) *gorm.DB

type Memory

type Memory struct {
	*amhist.BaseMemory

	Db             *gorm.DB
	Cfg            *Config
	SavePending    atomic.Int32
	SaveInProgress atomic.Bool
	GcInProgress   atomic.Bool
	Saved          atomic.Uint64
	// Value of Saved at the end of the last GC
	SavedGc atomic.Uint64
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(
	ctx context.Context, db *gorm.DB, mach am.Api, cfg Config,
	onErr func(err error),
) (*Memory, error)

func (*Memory) Config

func (m *Memory) Config() amhist.BaseConfig

Config is amhist.BaseMemory.Config.

func (*Memory) Dispose

func (m *Memory) Dispose() error

Dispose is amhist.BaseMemory.Dispose. TODO merge with ctx

func (*Memory) FindLatest

func (m *Memory) FindLatest(
	ctx context.Context, retTx bool, limit int, query amhist.Query,
) ([]*amhist.MemoryRecord, error)

FindLatest is amhist.BaseMemory.FindLatest.

func (*Memory) JoinState

func (m *Memory) JoinState(query *gorm.DB, name string) *gorm.DB

func (*Memory) JoinTransition

func (m *Memory) JoinTransition(query *gorm.DB) *gorm.DB

func (*Memory) Machine

func (m *Memory) Machine() am.Api

Machine is amhist.BaseMemory.Machine.

func (*Memory) MachineRecord

func (m *Memory) MachineRecord() *amhist.MachineRecord

MachineRecord is amhist.BaseMemory.MachineRecord.

func (*Memory) Match

func (m *Memory) Match(
	ctx context.Context, limit int, matcherFn MatcherFn,
) ([]*amhist.MemoryRecord, error)

Match returns the latest records that matches the given matcher function.

func (*Memory) Sync

func (m *Memory) Sync() error

Sync is amhist.BaseMemory.Sync.

type State

type State struct {
	ID        uint   `gorm:"primaryKey"`
	MachineID string `gorm:"index:machine_state"`
	// Index is the state index in the machine (not the tracked states index).
	Index int `gorm:"index:machine_state"`

	Name string
}

type Tick

type Tick struct {
	TimeID    uint64 `gorm:"primaryKey;autoIncrement:false;index:activated"`
	MachineID uint32 `gorm:"primaryKey;autoIncrement:false;index:activated"`
	StateID   uint   `gorm:"primaryKey;autoIncrement:false;index:activated"`

	State State

	Tick uint64
	// was the state activated in this transition?
	Activated bool `gorm:"index:activated"`
	// was the state deactivated in this transition?
	Deactivated bool
	// state is currently active
	Active bool
}

type Time

type Time struct {
	ID        uint64 `gorm:"primaryKey;autoIncrement:false"`
	MachineID uint32 `gorm:"primaryKey"`

	Ticks []Tick `gorm:"foreignKey:TimeID,MachineID;references:ID,MachineID"`

	// MutType is a mutation type.
	MutType am.MutationType
	// MTimeSum is a machine time sum after this transition.
	MTimeSum uint64
	// MTimeSum is a machine time sum after this transition for tracked states
	// only.
	MTimeTrackedSum uint64
	// MTimeDiffSum is a machine time difference for this transition.
	MTimeDiffSum uint64
	// MTimeDiffSum is a machine time difference for this transition for tracked
	// states only.
	MTimeTrackedDiffSum uint64
	// MTimeRecordDiffSum is a machine time difference since the previous
	// [amhist.TimeRecord].
	MTimeRecordDiffSum uint64
	// HTime is a human time in UTC.
	HTime time.Time
	// MTime is a machine time for tracked states after this mutation.
	MTimeTracked datatypes.JSON
	// MTimeTrackedDiff is a machine time diff compared to the previous mutation
	// (not a record). TODO make optional? can be generated
	MTimeTrackedDiff datatypes.JSON
	// TODO MTimeTrackedDiffCompact arpc-like clock encoding
	// MachTick is the machine tick at the time of this transition.
	MachTick uint32

	TxId string `gorm:"index:tx_id"`

	TxSourceTx   *string
	TxSourceMach *string
	TxIsAuto     bool
	TxIsAccepted bool
	TxIsCheck    bool
	TxIsBroken   bool
	TxQueueLen   uint16

	TxQueuedAt   *uint64
	TxExecutedAt *uint64

	TxCalled    datatypes.JSON
	TxArguments *datatypes.JSON
	// contains filtered or unexported fields
}

Time is a SQL version of amhist.TimeRecord.

Jump to

Keyboard shortcuts

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