version

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownVersion = errors.New("version is unknown")

Functions

func DoMigration

func DoMigration(name string, m MigrationMap) error

func GetCurrentVersion

func GetCurrentVersion(name string) int64

func SetVersion

func SetVersion(name string, version int64) (oldVersion int64, err error)

Types

type Migration added in v1.0.0

type Migration interface {
	Func() MigrationFunc
	TargetVersion() int64
}

func CreateSimpleMigration added in v1.0.0

func CreateSimpleMigration(targetVersion int64, f MigrationFunc) Migration

CreateSimpleMigration 可以用来快速创建一个 Migration 的helper 如果逻辑较为复杂,需要其他更多信息,也可以自行实现 Migration

type MigrationFunc added in v1.0.0

type MigrationFunc func() error

MigrationFunc 定义了迁移函数,实现的时候只能在当前goroutine内操作,不可创建其他goroutine,执行时会在RW事务中

func ChainMigration added in v1.0.0

func ChainMigration(fn ...MigrationFunc) MigrationFunc

ChainMigration 将多个 MigrationFunc 组合成一个 MigrationFunc ,每个 MigrationFunc 会按顺序执行

func CopyKeyValueByPattern added in v1.0.0

func CopyKeyValueByPattern(patternFunc localdb.KeyPatternFunc,
	operator func(key, value string) (string, string)) MigrationFunc

CopyKeyValueByPattern 遍历一个KeyPattern,对每个key/value执行operator,并把operator的返回值作为新的key/value,保留TTL 如果key变化了,不会删除老的key

func MigrationKeyValueByPattern added in v1.0.0

func MigrationKeyValueByPattern(patternFunc localdb.KeyPatternFunc,
	operator func(key, value string) (string, string)) MigrationFunc

MigrationKeyValueByPattern 遍历一个KeyPattern,对每个key/value执行operator,并把operator的返回值作为新的key/value,保留TTL 如果key变化了,会删除老的key

func MigrationValueByPattern added in v1.0.0

func MigrationValueByPattern(patternFunc localdb.KeyPatternFunc,
	operator func(key, value string) string) MigrationFunc

MigrationValueByPattern 遍历一个KeyPattern,对每个key/value执行operator,并把operator的返回值作为新的value,保留TTL

type MigrationMap added in v1.0.0

type MigrationMap interface {
	From(v int64) Migration
}

func NewMigrationMapFromMap added in v1.0.0

func NewMigrationMapFromMap(m map[int64]Migration) MigrationMap

Jump to

Keyboard shortcuts

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