dependency

package
v0.3.69 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BATCH_SIZE = 1000 // default batch size
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseOption

type BaseOption struct {
	Ignore         bool                          `json:"ignore"`        // ignore if exist
	Lock           bool                          `json:"lock"`          // lock row
	ReadOnly       bool                          `json:"readOnly"`      // read only
	Selects        []string                      `json:"selects"`       // select fields
	Omits          []string                      `json:"omits"`         // omit fields select omit
	Conds          []any                         `json:"conds"`         // conds where
	Page           IPage                         `json:"page"`          // page
	SearchAfter    ISearchAfter                  `json:"searchAfter"`   // search after
	BatchSize      int64                         `json:"batchSize"`     // exec by batch
	TableName      string                        `json:"tableName"`     // table name
	DataBase       string                        `json:"dataBase"`      // db name
	DbShardingKey  []any                         `json:"dbShardingKey"` // db sharding key
	TbShardingKey  []any                         `json:"tbShardingKey"` // table sharding key
	UpdatedMap     map[string]any                `json:"-"`             // updated map
	IDGenerate     func(ctx context.Context) any `json:"-"`             // id generate func
	IterativeFuncs []func(any)                   `json:"-"`             // iterative func
}

BaseOption base repo exec

func NewBaseOption added in v0.0.7

func NewBaseOption(opts ...BaseOptionFunc) *BaseOption

NewBaseOption with func

func (BaseOption) GetDataBase added in v0.1.0

func (opt BaseOption) GetDataBase(t IEntity) string

GetDataBase

func (BaseOption) GetTableName added in v0.1.0

func (opt BaseOption) GetTableName(t IEntity) string

GetTableName

func (BaseOption) Iterate added in v0.1.0

func (opt BaseOption) Iterate(v any)

Iterate

type BaseOptionFunc added in v0.0.7

type BaseOptionFunc func(o *BaseOption)

BaseOptionFunc base option func

func WithBatchSize added in v0.0.7

func WithBatchSize(v int64) BaseOptionFunc

WithBatchSize

func WithConds added in v0.0.7

func WithConds(vs ...any) BaseOptionFunc

WithConds

func WithDataBase added in v0.0.9

func WithDataBase(v string) BaseOptionFunc

WithDataBase

func WithDbShardingKey added in v0.0.11

func WithDbShardingKey(v ...any) BaseOptionFunc

WithDbShardingKey

func WithIDGenerate added in v0.0.10

func WithIDGenerate(v func(context.Context) any) BaseOptionFunc

WithIDGenerate

func WithIgnore added in v0.0.7

func WithIgnore(v bool) BaseOptionFunc

WithIgnore

func WithIterativeFunc added in v0.1.0

func WithIterativeFunc(v ...func(any)) BaseOptionFunc

WithIterativeFunc

func WithLock added in v0.0.7

func WithLock(v bool) BaseOptionFunc

WithLock

func WithOmits added in v0.0.7

func WithOmits(vs ...string) BaseOptionFunc

WithOmits

func WithPage added in v0.0.7

func WithPage(v IPage) BaseOptionFunc

WithPage

func WithReadOnly added in v0.0.7

func WithReadOnly(v bool) BaseOptionFunc

WithReadOnly

func WithSearchAfter added in v0.1.0

func WithSearchAfter(v ISearchAfter) BaseOptionFunc

WithSearchAfter

func WithSelects added in v0.0.7

func WithSelects(vs ...string) BaseOptionFunc

WithSelects

func WithTableName added in v0.0.9

func WithTableName(v string) BaseOptionFunc

WithTableName

func WithTbShardingKey added in v0.0.11

func WithTbShardingKey(v ...any) BaseOptionFunc

WithTbShardingKey

func WithUpdatedMap added in v0.3.58

func WithUpdatedMap(v map[string]any) BaseOptionFunc

WithUpdatedMap

type DbAction

type DbAction func(ctx context.Context) error

action

type EmptyPo added in v0.0.16

type EmptyPo struct{}

EmptyPo empty impl

func (EmptyPo) Database added in v0.0.16

func (p EmptyPo) Database() string

func (EmptyPo) ID added in v0.0.16

func (p EmptyPo) ID() any

func (EmptyPo) TableName added in v0.0.16

func (p EmptyPo) TableName() string

func (EmptyPo) ToJson added in v0.0.16

func (p EmptyPo) ToJson() string

func (EmptyPo) ToRow added in v0.0.16

func (p EmptyPo) ToRow() []string

type IBaseTask added in v0.3.7

type IBaseTask interface {
	GetTimeout() time.Duration
	GetBizId() uint64
	GetCategory() uint32
	GetName() string
}

type IBizRequest

type IBizRequest interface {
	GetBizId() int64
	ToUrlQuery() url.Values
}

IBizRequest business tag reqquest

type ICache added in v0.3.20

type ICache interface {
	// Get retrieves a value by its key.
	// key: The key of the cache item.
	// Returns: The value of the cache item, or nil if it doesn't exist.
	Get(key string) any

	// TTL gets the remaining time-to-live of a key.
	// key: The key of the cache item.
	// Returns: The remaining time-to-live of the key in seconds, or 0 if the key doesn't exist.
	TTL(key string) time.Duration

	// Set sets a cache item with an expiration timeout.
	// key: The key of the cache item.
	// val: The value of the cache item.
	// timeout: The expiration duration of the cache item.
	// Returns: An error if the set operation fails.
	Set(key string, val any, timeout time.Duration) error

	// SetNX sets a cache item only if the key does not already exist.
	// key: The key of the cache item.
	// val: The value of the cache item.
	// timeout: The expiration duration of the cache item.
	// Returns: True if the set operation succeeds, and false if the key already exists.
	SetNX(key string, val any, timeout time.Duration) (bool, error)

	// IsExist checks if a key exists in the cache.
	// key: The key of the cache item.
	// Returns: True if the key exists, otherwise false.
	IsExist(key string) bool

	// Delete removes a cache item by its key.
	// key: The key of the cache item.
	// Returns: An error if the deletion operation fails.
	Delete(key string) error
}

ICache interface defines the basic operations for a cache.

type ICacheShellKey added in v0.3.20

type ICacheShellKey interface {
	// GetCacheKey returns the cache's key value.
	// Returns a string which represents a unique identifier for the cache.
	// Suggest example:"{AppName}:{BizId}:{BusinessName}:{EntityName/ObjectName}:{OtherKey}"
	GetCacheKey() string

	// GetCacheDuration returns the cache's duration.
	// Returns a time.Duration indicating the cache's expiration time.
	GetCacheDuration() time.Duration

	// GetSkip returns a flag that indicates if the cache should be skipped.
	// Returns a bool where true signifies that the current request should bypass the cache and fetch data directly from the source.
	GetSkip() bool
}

ICacheShellKey interface defines the fundamental operations for a cache shell key. This interface is used to retrieve the cache key, cache duration, and a flag indicating whether to skip the cache.

type IDbSharding added in v0.0.9

type IDbSharding interface {
	DbSharding(keys ...any) string
}

IDbSharding split database by keys

type IEntity

type IEntity interface {
	IPo
}

type IEventMessage added in v0.3.4

type IEventMessage interface {
	ITask
	IMessage
}

type IGenerateID added in v0.0.10

type IGenerateID interface {
	SetID(id any)
}

IGenerateID customer id generate

type ILog added in v0.3.20

type ILog interface {
	Debug(ctx context.Context, msg string, args ...interface{})
	Info(ctx context.Context, msg string, args ...interface{})
	Warn(ctx context.Context, msg string, args ...interface{})
	Error(ctx context.Context, msg string, args ...interface{})
}

type IMQProducerRepository added in v0.3.4

type IMQProducerRepository[T IEventMessage] interface {
	IRepository[T]
	InsertAction(ctx context.Context, db string, t *T) func(context.Context) error
	WaitExecWithLock(ctx context.Context, t T, batch int) (string, int64, error)
	FindLockeds(ctx context.Context, locker string) ([]T, error)
}

IMQProducerRepository

type IMapping added in v0.1.0

type IMapping interface {
	GetMapping() string
}

Create a new index.

mapping := `{
	"settings":{
		"number_of_shards":1,
		"number_of_replicas":0
	},
	"mappings":{
		"properties":{
			"tags":{
				"type":"keyword"
			},
			"location":{
				"type":"geo_point"
			},
			"suggest_field":{
				"type":"completion"
			}
		}
	}
}`

type IMessage added in v0.3.4

type IMessage interface {
	GetTopic() string
	GetKey() []byte
	GetValue() []byte
}

type IPage

type IPage interface {
	GetPageIndex() int64
	GetPageSize() int64
	GetBegin() int64
	GetSize() int64
	GetSorts() []ISortField
}

IPage page request

type IPaginator

type IPaginator interface {
	IPage
	GetTotalRecord() int64
	GetTotalPage() int64
}

type IPo

type IPo interface {
	ID() any
	TableName() string
	Database() string
	ToRow() []string
	ToJson() string
}

IPo for db po struct

type IRange

type IRange interface {
	GetBeg() int64
	GetEnd() int64
}

IRange range

type IRepository

type IRepository[T IEntity] interface {
	BaseCreate(ctx context.Context, ps []*T, opts ...BaseOptionFunc) (int64, error)
	BaseSave(ctx context.Context, ps []*T, opts ...BaseOptionFunc) (int64, error)
	BaseUpdate(ctx context.Context, p *T, opts ...BaseOptionFunc) (int64, error)
	BaseGet(ctx context.Context, opts ...BaseOptionFunc) (*T, error)
	BaseDelete(ctx context.Context, p *T, opts ...BaseOptionFunc) (int64, error)
	BaseCount(ctx context.Context, opts ...BaseOptionFunc) (int64, error)
	BaseQuery(ctx context.Context, opts ...BaseOptionFunc) ([]T, error)
	BaseQueryWithCount(ctx context.Context, opts ...BaseOptionFunc) ([]T, int64, error)
}

IRepository repo

type ISearchAfter added in v0.1.0

type ISearchAfter interface {
	GetSortValues() []any
	GetSorts() []ISortField
}

type ISortField

type ISortField interface {
	GetField() string
	GetIsDesc() bool
}

ISortField sort field

type ITableSharding added in v0.0.9

type ITableSharding interface {
	TableSharding(keys ...any) string
	TableTotal() uint32
}

ITableSharding split table by keys

type ITask added in v0.2.3

type ITask interface {
	IEntity
	IBaseTask
}

type IUnitOfWork

type IUnitOfWork interface {
	Execute(ctx context.Context, fs ...DbAction) (e error)
}

IUnitOfWork trans

Jump to

Keyboard shortcuts

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