generic

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(ctx context.Context, log *slog.Logger, opts r.ConnectOpts) 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) (*datastore, error)

Types

type Datastore

type Datastore interface {
	IP() Storage[*metal.IP]
	Partition() Storage[*metal.Partition]
	Network() Storage[*metal.Network]
	FilesystemLayout() Storage[*metal.FilesystemLayout]
	Image() Storage[*metal.Image]
}

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
	// SetChanged sets the entity's changed time
	SetChanged(changed time.Time)
	// GetCreated sets the entity's creation time
	GetCreated() time.Time
	// SetCreated sets the entity's creation time
	SetCreated(created time.Time)
}

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

see https://go.googlesource.com/proposal/+/HEAD/design/43651-type-parameters.md#pointer-method-example for possible solution to prevent slices of pointers.

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, new, old 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