repo

package
v0.0.0-...-d49c957 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	Id        uint64                 `gorm:"primaryKey;autoIncrement:false;comment:分布式全局唯一 ID"`
	CreatedAt time.Time              `gorm:"type:datetime;comment:创建时间"`
	UpdatedAt time.Time              `gorm:"type:datetime;comment:更新时间"`
	DeletedAt gorm.DeletedAt         `gorm:"type:datetime;index;comment:删除时间"`
	Version   optimisticlock.Version `gorm:"default:1;comment:版本号(乐观锁专用)"`
}

type BaseRepo

type BaseRepo[E, T any] struct {
	DO  E
	PO  T
	DB  *gorm.DB
	Log *log.Helper
}

func (*BaseRepo[E, T]) Create

func (r *BaseRepo[E, T]) Create(ctx context.Context, do E) (E, error)

func (*BaseRepo[E, T]) Delete

func (r *BaseRepo[E, T]) Delete(ctx context.Context, id uint64) error

func (*BaseRepo[E, T]) DeleteByIDs

func (r *BaseRepo[E, T]) DeleteByIDs(ctx context.Context, ids []uint64) error

func (*BaseRepo[E, T]) Exists

func (r *BaseRepo[E, T]) Exists(ctx context.Context, fieldName string, fieldValue any, ignoreCase ...bool) (bool, error)

func (*BaseRepo[E, T]) Find

func (r *BaseRepo[E, T]) Find(ctx context.Context, id uint64, lockMode ...LockMode) (E, error)

func (*BaseRepo[E, T]) FindByField

func (r *BaseRepo[E, T]) FindByField(ctx context.Context, fieldName string, fieldValue any, args ...any) (E, error)

func (*BaseRepo[E, T]) Unique

func (r *BaseRepo[E, T]) Unique(ctx context.Context, id uint64, fieldName string, fieldValue any, ignoreCase ...bool) (bool, error)

func (*BaseRepo[E, T]) Update

func (r *BaseRepo[E, T]) Update(ctx context.Context, m map[string]any) (E, error)

type LockMode

type LockMode int32
const (
	// for update
	UPDATE LockMode = iota
	// lock in share mode
	SHARE
)

func ParseLockMode

func ParseLockMode(name string) (LockMode, error)

ParseLockMode attempts to convert a string to a LockMode.

func (LockMode) Ptr

func (x LockMode) Ptr() *LockMode

func (LockMode) String

func (x LockMode) String() string

String implements the Stringer interface.

type Repo

type Repo[E, T any] interface {
	// Exists determines whether po exists (whether to ignore case).
	Exists(ctx context.Context, fieldName string, fieldValue any, ignoreCase ...bool) (bool, error)
	// Unique determines whether po is unique (whether to ignore case).
	Unique(ctx context.Context, id uint64, fieldName string, fieldValue any, ignoreCase ...bool) (bool, error)
	// Find find po by id (with lockMode).
	Find(ctx context.Context, id uint64, lockMode ...LockMode) (E, error)
	// FindByField find po by fieldName and fieldValue (with ignoreCase and/or lockMode).
	FindByField(ctx context.Context, fieldName string, fieldValue any, args ...any) (E, error)
	// Create create po.
	Create(ctx context.Context, do E) (E, error)
	// Update update po.
	Update(ctx context.Context, m map[string]any) (E, error)
	// Delete delete po.
	Delete(ctx context.Context, id uint64) error
	// DeleteByIDs delete pos.
	DeleteByIDs(ctx context.Context, ids []uint64) error
}

Repo base repository.

Jump to

Keyboard shortcuts

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