generic

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsnPoolRange added in v0.0.2

func AsnPoolRange(min, max uint) dataStoreOption

func Initialize

func Initialize(ctx context.Context, log *slog.Logger, opts r.ConnectOpts, dsOpts ...dataStoreOption) error

func Migrate

func Migrate(ctx context.Context, opts r.ConnectOpts, log *slog.Logger, targetVersion *int, dry bool) error

Migrate runs database migrations and puts the database into read only mode for demoted runtime users.

func MustRegisterMigration

func MustRegisterMigration(m Migration)

MustRegisterMigration registers a migration and panics when a problem occurs

func New

func New(log *slog.Logger, opts r.ConnectOpts, dsOpts ...dataStoreOption) (*datastore, error)

func VrfPoolRange added in v0.0.2

func VrfPoolRange(min, max uint) dataStoreOption

Types

type Datastore

type Datastore interface {
	IP() Storage[*metal.IP]
	Machine() Storage[*metal.Machine]
	Size() Storage[*metal.Size]
	SizeReservation() Storage[*metal.SizeReservation]
	Partition() Storage[*metal.Partition]
	Network() Storage[*metal.Network]
	FilesystemLayout() Storage[*metal.FilesystemLayout]
	Image() Storage[*metal.Image]
	Switch() Storage[*metal.Switch]
	SwitchStatus() Storage[*metal.SwitchStatus]
	Event() Storage[*metal.ProvisioningEventContainer]

	// Pools
	AsnPool() *integerPool
	VrfPool() *integerPool

	Version(ctx context.Context) (string, error)
}

type Entity

type Entity interface {
	// GetID returns the entity's id
	GetID() string
	// SetID sets the entity's id
	SetID(id string)
	// GetChanged returns the entity's changed time
	GetChanged() time.Time
	// GetCreated returns the entity's creation time
	GetCreated() time.Time
	// GetGeneration returns the entity's generation
	GetGeneration() uint64
}

Entity is an interface that allows metal entities to be created and stored into the database with the generic creation and update functions.

type EntityQuery

type EntityQuery func(q r.Term) r.Term

type Migration

type Migration struct {
	Name    string
	Version int
	Up      migrateFunc
}

Migration defines a database migration

type Storage

type Storage[E Entity] interface {
	Create(ctx context.Context, e E) (E, error)
	Update(ctx context.Context, e E) error
	Upsert(ctx context.Context, e E) error
	Delete(ctx context.Context, e E) error
	Get(ctx context.Context, id string) (E, error)
	Find(ctx context.Context, queries ...EntityQuery) (E, error)
	List(ctx context.Context, queries ...EntityQuery) ([]E, error)
}

Directories

Path Synopsis
Package migrations contains migration functions for migrating the RethinkDB.
Package migrations contains migration functions for migrating the RethinkDB.

Jump to

Keyboard shortcuts

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