Help us shape the future of Go! Take the 2026 Go Developer Survey

datastore

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PropertyTypeUnknown = iota
	PropertyTypeInt
	PropertyTypeDouble
	PropertyTypeString
	PropertyTypeStruct
	PropertyTypeProto
	PropertyTypeBoolean
)

Variables

View Source
var (
	ErrCreatingDatastore    = errors.New("error creating datastore")
	ErrUnsupportedDatastore = errors.New("unsupported datastore type")
)

Functions

func Register

func Register(t string, fn func(config any) (Connector, error))

Types

type ArtifactTypeMap

type ArtifactTypeMap map[string]int32

type Connector

type Connector interface {
	Type() string
	Connect(spec *Spec) (RepoSet, error)
	RunMigrations(spec *Spec) error
	// Reconnect creates a fresh RepoSet after the database has been recreated
	// (e.g., by RunMigrations recovering from data loss). It must not re-run
	// migrations; callers are responsible for calling RunMigrations first.
	Reconnect(spec *Spec) (RepoSet, error)
}

func NewConnector

func NewConnector(t string, config any) (Connector, error)

type ContextTypeMap

type ContextTypeMap map[string]int32

type ExecutionTypeMap

type ExecutionTypeMap map[string]int32

type PropertyType

type PropertyType int32

PropertyType is the data type of a property's value.

type RepoSet

type RepoSet interface {
	// TypeMap returns a map of type names to IDs
	TypeMap() map[string]int32
	Repository(t reflect.Type) (any, error)
}

RepoSet holds repository implementions.

type Spec

type Spec struct {
	// Maps artifact type names to an initializer.
	ArtifactTypes map[string]*SpecType

	// Maps context type names to an initializer.
	ContextTypes map[string]*SpecType

	// Maps execution type names to an initializer.
	ExecutionTypes map[string]*SpecType

	// Any repo initialization functions that don't map to a type can be
	// added here.
	Others []any
}

Spec is the specification for the datastore. Each entry

func NewSpec

func NewSpec() *Spec

NewSpec returns an empty Spec instance.

func (*Spec) AddArtifact

func (s *Spec) AddArtifact(name string, t *SpecType) *Spec

AddArtifact adds an artifact type to the spec.

func (*Spec) AddContext

func (s *Spec) AddContext(name string, t *SpecType) *Spec

AddContext adds a context type to the spec.

func (*Spec) AddExecution

func (s *Spec) AddExecution(name string, t *SpecType) *Spec

AddExecution adds an execution type to the spec.

func (*Spec) AddOther

func (s *Spec) AddOther(initFn any) *Spec

AddOther adds a repo initializer to the spec.

func (*Spec) AllNames

func (s *Spec) AllNames() []string

AllNames returns all the type names in the spec.

type SpecType

type SpecType struct {
	// InitFn is a pointer to an initialization function that returns the
	// repository instance and an optional error.
	//
	// Data Store implementations must pass arguments to the initialization
	// functions that are required by the repository (database handles,
	// HTTP clients, etc.) and should also provide values for the following
	// types:
	//
	//   - int64: type id
	//   - ArtifactTypeMap: Map of all artifact names to type IDs
	//   - ContextTypeMap: Map of all context names to type IDs
	//   - ExecutionTypeMap: Map of all execution names to type IDs
	InitFn any

	// Defined (non-custom) properties of the type.
	Properties map[string]PropertyType
}

SpecType is a single type in the spec.

func NewSpecType

func NewSpecType(initFn any) *SpecType

NewSpecType creates a SpecType instance.

func (*SpecType) AddBoolean

func (st *SpecType) AddBoolean(name string) *SpecType

AddBoolean adds a boolean property to the type spec.

func (*SpecType) AddDouble

func (st *SpecType) AddDouble(name string) *SpecType

AddDouble adds a double property to the type spec.

func (*SpecType) AddInt

func (st *SpecType) AddInt(name string) *SpecType

AddInt adds an int property to the type spec.

func (*SpecType) AddProto

func (st *SpecType) AddProto(name string) *SpecType

AddProto adds a proto property to the type spec.

func (*SpecType) AddString

func (st *SpecType) AddString(name string) *SpecType

AddString adds a string property to the type spec.

func (*SpecType) AddStruct

func (st *SpecType) AddStruct(name string) *SpecType

AddStruct adds a struct property to the type spec.

Jump to

Keyboard shortcuts

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