Documentation ¶
Index ¶
- Constants
- Variables
- func SetAudited(ctx context.Context, e any)
- func SetAuditedMany[T any](ctx context.Context, data []T) []any
- func SetAuditedManyPtr[T any](ctx context.Context, data []T) []any
- func WithHardDelete(ctx context.Context) context.Context
- type AuditEntityBase
- type CreationAuditedEntity
- type DeletionAuditedEntity
- type Entity
- type EntityBase
- type FullAuditEntityBase
- type OrderEntity
- type OrderEntityBase
- type PagedItems
- type PagedResult
- type Repository
- type SoftDeleteEntity
- type UpdationAuditedEntity
- type WithExtraArrayEntity
- type WithExtraEntity
- func (m *WithExtraEntity) GetFloat32(key string) float32
- func (m *WithExtraEntity) GetInt(key string) int
- func (m *WithExtraEntity) GetProperty(key string, value interface{}) (bool, error)
- func (m *WithExtraEntity) GetString(key string) string
- func (m *WithExtraEntity) SetFloat32(key string, value float32)
- func (m *WithExtraEntity) SetInt(key string, value int)
- func (m *WithExtraEntity) SetProperty(key string, value interface{})
- func (m *WithExtraEntity) SetString(key string, value string)
Constants ¶
View Source
const SoftDeleteFieldName = "isDeleted"
Variables ¶
View Source
var (
ErrEntityNotFound = errors.New("entity not found")
)
Functions ¶
func SetAudited ¶
func SetAuditedMany ¶
SetAuditedMany is a helper function to set audit fields for a slice of pointers. T is not struct ptr
func SetAuditedManyPtr ¶
SetAuditedManyPtr is a helper function to set audit fields for a slice of pointers. T is struct ptr
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 ¶
func (e AuditEntityBase) GetId() primitive.ObjectID
type CreationAuditedEntity ¶
type DeletionAuditedEntity ¶
type EntityBase ¶
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 ¶
func NewPagedItems ¶
func NewPagedItems[T any](items []T, hasNext bool) PagedItems[T]
type PagedResult ¶
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 WithExtraArrayEntity ¶
type WithExtraArrayEntity struct {
Data []string `bson:"data,omitempty"`
}
func (*WithExtraArrayEntity) Append ¶
func (a *WithExtraArrayEntity) Append(str string)
type WithExtraEntity ¶
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)
Click to show internal directories.
Click to hide internal directories.