ddd

package
v0.0.0-...-9a83fbb Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SoftDeleteFieldName = "isDeleted"

Variables

View Source
var (
	ErrEntityNotFound = errors.New("entity not found")
)

Functions

func SetAudited

func SetAudited(ctx context.Context, e any)

func SetAuditedMany

func SetAuditedMany[T any](ctx context.Context, data []T) []any

SetAuditedMany is a helper function to set audit fields for a slice of pointers. T is not struct ptr

func SetAuditedManyPtr

func SetAuditedManyPtr[T any](ctx context.Context, data []T) []any

SetAuditedManyPtr is a helper function to set audit fields for a slice of pointers. T is struct ptr

func WithHardDelete

func WithHardDelete(ctx context.Context) context.Context

Types

type AuditEntityBase

type AuditEntityBase struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	CreatorId primitive.ObjectID `bson:"creatorId,omitempty"`
	CreatedAt time.Time          `bson:"createdAt"`
}

func (*AuditEntityBase) Creating

func (e *AuditEntityBase) Creating(ctx context.Context)

func (AuditEntityBase) GetId

type CreationAuditedEntity

type CreationAuditedEntity interface {
	Creating(ctx context.Context)
}

type DeletionAuditedEntity

type DeletionAuditedEntity interface {
	Entity
	Deleting(ctx context.Context)
}

type Entity

type Entity interface {
	GetId() primitive.ObjectID
}

type EntityBase

type EntityBase struct {
	ID primitive.ObjectID `bson:"_id,omitempty"`
}

func (*EntityBase) GetId

func (e *EntityBase) GetId() primitive.ObjectID

type FullAuditEntityBase

type FullAuditEntityBase struct {
	AuditEntityBase `bson:",inline"`
	UpdatedAt       time.Time          `bson:"updatedAt,omitempty"`
	UpdaterId       primitive.ObjectID `bson:"updaterId,omitempty"`
}

func (*FullAuditEntityBase) Updating

func (e *FullAuditEntityBase) Updating(ctx context.Context)

type OrderEntity

type OrderEntity interface {
	GetOrder() float64
}

type OrderEntityBase

type OrderEntityBase struct {
	Order float64 `bson:"order"`
}

func (OrderEntityBase) GetOrder

func (e OrderEntityBase) GetOrder() float64

type PagedItems

type PagedItems[T any] struct {
	Items   []T  `json:"items"`
	HasNext bool `json:"hasNext"`
}

func NewPagedItems

func NewPagedItems[T any](items []T, hasNext bool) PagedItems[T]

type PagedResult

type PagedResult[T any] struct {
	TotalCount int64 `json:"totalCount"`
	Items      []T   `json:"items"`
}

func NewPagedResult

func NewPagedResult[T any](totalCount int64, items []T) PagedResult[T]

type Repository

type Repository[TEntity any] interface {
	GetAll(ctx context.Context) []TEntity
	Get(ctx context.Context, id primitive.ObjectID) *TEntity
	FirstOrDefault(ctx context.Context, id primitive.ObjectID) *TEntity
	GetPagedList(ctx context.Context, p *x.PageAndSort) ([]TEntity, int64)

	Set(ctx context.Context, id primitive.ObjectID, data *TEntity) int
	GetMany(ctx context.Context, ids []primitive.ObjectID) []TEntity
	Insert(ctx context.Context, entity *TEntity) primitive.ObjectID
	// InsertMany ignoreErr: 是否忽略批量插入时的错误, 一般为false, 当导入时忽略重复key的时候可以设为true
	InsertMany(ctx context.Context, entitis []TEntity, ignoreErr bool) []primitive.ObjectID
	Exists(ctx context.Context, id primitive.ObjectID) bool
	ExistsByField(ctx context.Context, field string, v any) bool
	Update(ctx context.Context, id primitive.ObjectID, entity *TEntity) int
	Delete(ctx context.Context, id primitive.ObjectID) int
	DeleteMany(ctx context.Context, ids []primitive.ObjectID) int

	Count(ctx context.Context) int64

	FindByRegex(ctx context.Context, field, regex string, p *x.PageAndSort) []TEntity
	UpsertByField(ctx context.Context, field string, fieldValue any, newObj *TEntity) primitive.ObjectID
}

type SoftDeleteEntity

type SoftDeleteEntity struct {
	IsDeleted  bool               `bson:"isDeleted"`
	DeletionAt time.Time          `bson:"deletedAt,omitempty"`
	DeleterId  primitive.ObjectID `bson:"deleterId,omitempty"`
}

func (*SoftDeleteEntity) Deleting

func (e *SoftDeleteEntity) Deleting(ctx context.Context)

type UpdationAuditedEntity

type UpdationAuditedEntity interface {
	Updating(ctx context.Context)
}

type WithExtraArrayEntity

type WithExtraArrayEntity struct {
	Data []string `bson:"data,omitempty"`
}

func (*WithExtraArrayEntity) Append

func (a *WithExtraArrayEntity) Append(str string)

type WithExtraEntity

type WithExtraEntity struct {
	Data map[string]string `bson:"data,omitempty"`
}

func (*WithExtraEntity) GetFloat32

func (m *WithExtraEntity) GetFloat32(key string) float32

func (*WithExtraEntity) GetInt

func (m *WithExtraEntity) GetInt(key string) int

func (*WithExtraEntity) GetProperty

func (m *WithExtraEntity) GetProperty(key string, value interface{}) (bool, error)

func (*WithExtraEntity) GetString

func (m *WithExtraEntity) GetString(key string) string

func (*WithExtraEntity) SetFloat32

func (m *WithExtraEntity) SetFloat32(key string, value float32)

func (*WithExtraEntity) SetInt

func (m *WithExtraEntity) SetInt(key string, value int)

func (*WithExtraEntity) SetProperty

func (m *WithExtraEntity) SetProperty(key string, value interface{})

func (*WithExtraEntity) SetString

func (m *WithExtraEntity) SetString(key string, value string)

Jump to

Keyboard shortcuts

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