sharding

package
v0.0.0-...-098be99 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	PrimaryKey string
	Selects    []string
	Where      clause.Expression
	Order      []Order
	Group      []string
}

func (*Condition) DB

func (c *Condition) DB(db *gorm.DB) *gorm.DB

type Information

type Information struct {
	ID          int64     `gorm:""`
	Name        string    `gorm:"type:varchar(255);not null;index"`
	Table       string    `gorm:"type:varchar(255);not null;index"`
	CreatedTime time.Time `gorm:"type:datetime"`
	UpdatedTime time.Time `gorm:"type:datetime"`
}

type Item

type Item struct {
	PrimaryKey    any
	ShardingTable string
	Order         []Order
	Group         []string
	OrderValues   Record
	GroupValues   Record
}

type Items

type Items []*Item

func (Items) Len

func (c Items) Len() int

func (Items) Less

func (c Items) Less(i, j int) bool

func (Items) Swap

func (c Items) Swap(i, j int)

type Option

type Option func(s *sharding)

func WithCreateTable

func WithCreateTable(createTable bool, createTableScript string) Option

func WithPrimaryKey

func WithPrimaryKey(primaryKey string) Option

func WithStorage

func WithStorage(storage Storage) Option

func WithStrategy

func WithStrategy(strategy Strategy) Option

type Order

type Order struct {
	Column string
	Desc   bool
}

func (*Order) String

func (o *Order) String() string

type Record

type Record map[string]any

func (Record) Boolean

func (r Record) Boolean(key string) bool

func (Record) Float

func (r Record) Float(key string) float64

func (Record) Int

func (r Record) Int(key string) int

func (Record) String

func (r Record) String(key string) string

func (Record) Time

func (r Record) Time(key string) time.Time

func (Record) Uint

func (r Record) Uint(key string) uint

type Sharding

type Sharding interface {
	InitializeSharding(ctx context.Context) error
	Insert(ctx context.Context, record Record) error
	BatchInsert(ctx context.Context, records []Record) error
	Find(ctx context.Context, condition *Condition, offset, limit int) ([]Record, int64, error)
	FindOne(ctx context.Context, condition *Condition) (Record, error)
	Count(ctx context.Context, condition *Condition) (int64, error)
}

func NewSharding

func NewSharding(db *gorm.DB, name string, options ...Option) Sharding

type Storage

type Storage interface {
	Count(ctx context.Context, name string, condition *Condition) int64
	Get(ctx context.Context, name string, condition *Condition, offset, limit int) ([]*Item, error)
	Exist(ctx context.Context, name string, condition *Condition) bool
	Put(ctx context.Context, name string, condition *Condition, items []*Item) error
	Del(ctx context.Context, name string, condition *Condition)
}

type Strategy

type Strategy interface {
	TableSuffix(record Record, column string) (string, error)
}

type StrategyFunc

type StrategyFunc func(record Record, column string) (string, error)

func (StrategyFunc) TableSuffix

func (f StrategyFunc) TableSuffix(record Record, column string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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