plugins

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID             = errors.New("invalid id format")
	ErrIDGeneratorNotFound   = errors.New("id generator not found")
	ErrShardingModelNotFound = errors.New("sharding table model not found when migrating")
	ErrDiffSuffixDML         = errors.New("can not query different suffix table in one sql")
	ErrMissingShardingKey    = errors.New("sharding key required and use operator =")
	ErrColumnAndExprMisMatch = errors.New("column names and expressions mismatch")
)

Functions

This section is empty.

Types

type TableSharding

type TableSharding interface {
	gorm.Plugin

	ShardingIDGen(ctx context.Context) (id uint64, err error)
	ShardingByValues(ctx context.Context, src []map[string]any) (dst map[string][]map[string]any, err error)
	ShardingByModelList(ctx context.Context, src ...any) (dst map[string][]any, err error)
}

func DefaultTableSharding

func DefaultTableSharding(config TableShardingConfig) TableSharding

type TableShardingConfig

type TableShardingConfig struct {
	// Database name
	Database string

	// Table name
	Table string

	// ShardingKeys required, specifies the table columns you want to use for sharding the table rows.
	// For example, for a product order table, you may want to split the rows by `user_id`.
	ShardingKeys []string

	// ShardingKeyExpr optional, specifies how to calculate sharding key by columns, e.g. tenant_id << 16 | user_id
	ShardingKeyExpr gval.Evaluable

	// ShardingKeyByRawValue optional, specifies sharding key with snake values, e.g. xxx_region1_az1, xxx_region1_az2
	ShardingKeyByRawValue bool

	// ShardingKeysForMigrating optional, specifies all sharding keys
	ShardingKeysForMigrating []string

	// NumberOfShards required, specifies how many tables you want to sharding.
	NumberOfShards uint

	// CustomSuffix optional, specifies shard table a custom suffix, e.g. user_%02d means <main_table_name>_user_01
	CustomSuffix string

	// PrimaryKeyGenerator optional, generates id if id is a sharding key and is zero
	PrimaryKeyGenerator idgen.Generator
}

Jump to

Keyboard shortcuts

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