ops

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ops implements the 14 migration operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecAddCollection

func ExecAddCollection(doc *tomledit.DocumentNode, op Op) error

func ExecAddField

func ExecAddField(doc *tomledit.DocumentNode, op Op) error

func ExecAppend

func ExecAppend(doc *tomledit.DocumentNode, op Op) error

func ExecDropCollection

func ExecDropCollection(doc *tomledit.DocumentNode, op Op) error

func ExecMergeDefaults

func ExecMergeDefaults(doc *tomledit.DocumentNode, op Op) error

func ExecMergeDefaultsByKey

func ExecMergeDefaultsByKey(doc *tomledit.DocumentNode, op Op) error

func ExecMoveField

func ExecMoveField(doc *tomledit.DocumentNode, op Op) error

func ExecRaw

func ExecRaw(doc *tomledit.DocumentNode, op Op) error

func ExecRemoveField

func ExecRemoveField(doc *tomledit.DocumentNode, op Op) error

func ExecRemoveWhere

func ExecRemoveWhere(doc *tomledit.DocumentNode, op Op) error

func ExecRenameField

func ExecRenameField(doc *tomledit.DocumentNode, op Op) error

func ExecSetValue

func ExecSetValue(doc *tomledit.DocumentNode, op Op) error

func ExecSetValueWhere

func ExecSetValueWhere(doc *tomledit.DocumentNode, op Op) error

func ExecTransform

func ExecTransform(doc *tomledit.DocumentNode, op Op) error

func Execute

func Execute(doc *tomledit.DocumentNode, op Op) error

func Matches

func Matches(item map[string]any, where any, mode MatchMode, index int, arrayLen int) bool

Matches checks whether item matches the where clause according to the given mode. arrayLen is the total array length, needed for negative index normalization. index is the current element's position in the array.

Types

type DownOp

type DownOp struct {
	Irreversible bool
	Ops          []Op
}

type MatchMode

type MatchMode string
const (
	MatchSubset    MatchMode = "subset"
	MatchExact     MatchMode = "exact"
	MatchAll       MatchMode = "all"
	MatchIndex     MatchMode = "index"
	MatchHasKey    MatchMode = "has_key"
	MatchNotHasKey MatchMode = "not_has_key"
	MatchRegex     MatchMode = "regex"
)

type Migration

type Migration struct {
	Description string
	Structure   []Op
	Data        []Op
}

func ParseMigration

func ParseMigration(data []byte) (*Migration, error)

type Op

type Op struct {
	Type    OpType
	Section string // "structure" or "data"

	// Common
	Path string
	Down *DownOp

	// add_field
	FieldType string // "type" field from TOML
	Default   any

	// rename_field, move_field
	From string
	To   string

	// add_collection
	Fields map[string]any

	// set_value, raw
	Value   any
	Content string

	// set_value_where, remove_where
	Where     any
	MatchMode string
	Set       map[string]any

	// transform
	Expr string

	// merge_defaults_by_key
	MatchField string
	Defaults   []map[string]any
}

type OpType

type OpType string
const (
	OpAddField           OpType = "add_field"
	OpRemoveField        OpType = "remove_field"
	OpRenameField        OpType = "rename_field"
	OpMoveField          OpType = "move_field"
	OpAddCollection      OpType = "add_collection"
	OpDropCollection     OpType = "drop_collection"
	OpSetValue           OpType = "set_value"
	OpSetValueWhere      OpType = "set_value_where"
	OpRemoveWhere        OpType = "remove_where"
	OpAppend             OpType = "append"
	OpTransform          OpType = "transform"
	OpMergeDefaults      OpType = "merge_defaults"
	OpMergeDefaultsByKey OpType = "merge_defaults_by_key"
	OpRaw                OpType = "raw"
)

Jump to

Keyboard shortcuts

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