labels

package
v0.19.906 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLabels

func WithLabels(column string, lbls Labels) func(*gorm.DB) *gorm.DB

WithLabels returns a GORM scope that filters rows where the JSONB column contains all the specified key-value pairs (PostgreSQL @> containment). A value of "*" is treated as a wildcard — it matches any value for that key (uses jsonb_exists() to check key existence). Returns a no-op scope if lbls is nil or empty.

Types

type Labeled

type Labeled struct {
	Labels Labels `json:"labels,omitzero" gorm:"default null" temporaljson:"labels,omitzero,omitempty"`
}

Labeled is an embeddable struct for any GORM model that supports labels. Embed it to get a consistent JSONB labels column with standard tags.

type Labels

type Labels map[string]string

Labels defines a custom type for map[string]string that works with JSONB in GORM.

func ParseLabelsQuery

func ParseLabelsQuery(raw string) Labels

ParseLabelsQuery parses a comma-separated "key:value" string into Labels. Returns nil for empty input. Entries without a separator are treated as wildcard key-only filters (value set to "*"). Supports both ":" and "=" as key-value separators. Splits on the first separator only, so values may contain colons or equals. A value of "*" means "match any value for this key" (wildcard).

func (Labels) GormDataType

func (l Labels) GormDataType() string

GormDataType returns the GORM data type for this field.

func (Labels) HasLabel

func (l Labels) HasLabel(key, value string) bool

HasLabel returns true if the label with the given key and value exists.

func (*Labels) Merge

func (l *Labels) Merge(other Labels)

Merge adds all key-value pairs from other into the receiver, overwriting existing keys.

func (*Labels) RemoveKeys

func (l *Labels) RemoveKeys(keys []string)

RemoveKeys removes the specified keys from the labels.

func (*Labels) Scan

func (l *Labels) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database deserialization.

func (Labels) Value

func (l Labels) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

Jump to

Keyboard shortcuts

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