db

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptimisticLockErrorMsg = "the object has been modified; please apply your changes to the latest version and try again"
)

Variables

This section is empty.

Functions

func ContextWithPartitionID

func ContextWithPartitionID(ctx context.Context, partitionID string) context.Context

func PartitionIDFromContext

func PartitionIDFromContext(ctx context.Context) string

Types

type Criteria

type Criteria struct {
	Name      string
	Namespace *string
	// After is non-inclusive
	After uint
	// Before is inclusive
	Before            uint
	NoResourceVersion bool
	Limit             int64
	LabelSelector     labels.Selector
	FieldSelector     fields.Selector
	IncludeDeleted    bool
	IncludeGC         bool
	PartitionID       string
	// contains filtered or unexported fields
}

type DB

type DB interface {
	Transaction(ctx context.Context, do func(ctx context.Context) error) error
	Watch(ctx context.Context, criteria WatchCriteria) (chan Record, error)
	Get(ctx context.Context, criteria Criteria) ([]Record, uint, error)
	Insert(ctx context.Context, rec *Record) error
	Start(ctx context.Context) error
}

type Factory

type Factory struct {
	AutoMigrate bool
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory(schema *runtime.Scheme, dsn string, opts ...FactoryOption) (*Factory, error)

func (*Factory) Check

func (f *Factory) Check(req *http.Request) error

func (*Factory) Name

func (f *Factory) Name() string

func (*Factory) NewDBStrategy

func (f *Factory) NewDBStrategy(obj types.Object) (strategy.CompleteStrategy, error)

func (*Factory) Scheme

func (f *Factory) Scheme() *runtime.Scheme

type FactoryOption

type FactoryOption func(*Factory)

func WithEncryptionConfiguration

func WithEncryptionConfiguration(ctx context.Context, configPath string, apiServerId string) (FactoryOption, error)

func WithMigrationTimeout

func WithMigrationTimeout(timeout time.Duration) FactoryOption

WithMigrationTimeout sets a timeout for the initial database migration if auto migration is enabled.

func WithPartitionIDRequired

func WithPartitionIDRequired() FactoryOption

WithPartitionIDRequired will configure the all DB strategies created from this factory to require a partition ID when querying the database.

type GormDB

type GormDB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(tableName string, gvk schema.GroupVersionKind, db *gorm.DB, transformers map[schema.GroupKind]value.Transformer) *GormDB

func (*GormDB) Get

func (g *GormDB) Get(ctx context.Context, criteria Criteria) ([]Record, uint, error)

func (*GormDB) Insert

func (g *GormDB) Insert(ctx context.Context, rec *Record) error

func (*GormDB) Start

func (g *GormDB) Start(ctx context.Context) (err error)

func (*GormDB) Transaction

func (g *GormDB) Transaction(ctx context.Context, do func(ctx context.Context) error) error

func (*GormDB) Watch

func (g *GormDB) Watch(ctx context.Context, criteria WatchCriteria) (chan Record, error)

type Record

type Record struct {
	ID          uint
	Kind        string
	Version     string
	APIGroup    string
	Name        string `gorm:"index:,composite:idx_ns_name_id"`
	Namespace   string `gorm:"index:,composite:idx_ns_name_id"`
	UID         string
	Generation  int
	Previous    *uint `gorm:"index:,unique"`
	Create      bool
	Created     time.Time
	Updated     time.Time
	Deleted     *time.Time
	Removed     *time.Time
	Garbage     bool `gorm:"index:,composite:idx_garbage;not null;default:0"`
	Latest      bool `gorm:"index:,composite:idx_latest;default:0"`
	Metadata    datatypes.JSON
	Data        datatypes.JSON
	Status      datatypes.JSON
	PartitionID string `gorm:"index:,composite:idx_ns_name_id"`
}

type Strategy

type Strategy struct {
	// contains filtered or unexported fields
}

func NewStrategy

func NewStrategy(scheme *runtime.Scheme, obj runtime.Object, tableName string, db *gorm.DB, transformers map[schema.GroupKind]value.Transformer, partitionIDRequired bool) (*Strategy, error)

func (*Strategy) Create

func (s *Strategy) Create(ctx context.Context, obj types.Object) (result types.Object, err error)

func (*Strategy) Delete

func (s *Strategy) Delete(ctx context.Context, obj types.Object) (types.Object, error)

func (*Strategy) Destroy

func (s *Strategy) Destroy()

func (*Strategy) Get

func (s *Strategy) Get(ctx context.Context, namespace, name string) (types.Object, error)

func (*Strategy) GetToList

func (s *Strategy) GetToList(ctx context.Context, namespace, name string) (types.ObjectList, error)

func (*Strategy) List

func (s *Strategy) List(ctx context.Context, namespace string, opts storage.ListOptions) (types.ObjectList, error)

func (*Strategy) New

func (s *Strategy) New() types.Object

func (*Strategy) NewList

func (s *Strategy) NewList() types.ObjectList

func (*Strategy) Scheme

func (s *Strategy) Scheme() *runtime.Scheme

func (*Strategy) Start

func (s *Strategy) Start(ctx context.Context)

func (*Strategy) Update

func (s *Strategy) Update(ctx context.Context, obj types.Object) (types.Object, error)

func (*Strategy) UpdateStatus

func (s *Strategy) UpdateStatus(ctx context.Context, obj types.Object) (types.Object, error)

func (*Strategy) Watch

func (s *Strategy) Watch(ctx context.Context, namespace string, opts storage.ListOptions) (<-chan watch.Event, error)

type TableNamer

type TableNamer interface {
	TableName() string
}

type WatchCriteria

type WatchCriteria struct {
	Name          string
	Namespace     *string
	After         uint
	LabelSelector labels.Selector
	FieldSelector fields.Selector
	PartitionID   string
}

Directories

Path Synopsis
Package glogrus provides a gorm logger that wraps a logrus.Logger.
Package glogrus provides a gorm logger that wraps a logrus.Logger.

Jump to

Keyboard shortcuts

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