Documentation
¶
Index ¶
- type AfterHookFn
- type BeforeHookFn
- type Finder
- func (f *Finder[T]) Count(ctx context.Context, opts ...options.Lister[options.CountOptions]) (int64, error)
- func (f *Finder[T]) Distinct(ctx context.Context, fieldName string, ...) *mongo.DistinctResult
- func (f *Finder[T]) DistinctWithParse(ctx context.Context, fieldName string, result any, ...) error
- func (f *Finder[T]) Filter(filter any) IFinder[T]
- func (f *Finder[T]) Find(ctx context.Context, opts ...options.Lister[options.FindOptions]) ([]*T, error)
- func (f *Finder[T]) FindOne(ctx context.Context, opts ...options.Lister[options.FindOneOptions]) (*T, error)
- func (f *Finder[T]) FindOneAndUpdate(ctx context.Context, opts ...options.Lister[options.FindOneAndUpdateOptions]) (*T, error)
- func (f *Finder[T]) GetCollection() *mongo.Collection
- func (f *Finder[T]) Limit(limit int64) IFinder[T]
- func (f *Finder[T]) ModelHook(modelHook any) IFinder[T]
- func (f *Finder[T]) PostActionHandler(ctx context.Context, globalOpContext *operation.OpContext, ...) (err error)
- func (f *Finder[T]) PreActionHandler(ctx context.Context, globalOpContext *operation.OpContext, ...) (err error)
- func (f *Finder[T]) RegisterAfterHooks(hooks ...AfterHookFn[T]) IFinder[T]
- func (f *Finder[T]) RegisterBeforeHooks(hooks ...BeforeHookFn[T]) IFinder[T]
- func (f *Finder[T]) Skip(skip int64) IFinder[T]
- func (f *Finder[T]) Sort(sort any) IFinder[T]
- func (f *Finder[T]) Updates(update any) IFinder[T]
- type IFinder
- type OpContext
- type OpContextOption
- func WithDoc[T any](doc *T) OpContextOption[T]
- func WithDocs[T any](docs []*T) OpContextOption[T]
- func WithFields[T any](fields []*field.Filed) OpContextOption[T]
- func WithModelHook[T any](modelHook any) OpContextOption[T]
- func WithMongoOptions[T any](mongoOptions any) OpContextOption[T]
- func WithResult[T any](result any) OpContextOption[T]
- func WithStartTime[T any](startTime time.Time) OpContextOption[T]
- func WithUpdates[T any](updates any) OpContextOption[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AfterHookFn ¶ added in v2.4.0
type BeforeHookFn ¶ added in v2.4.0
type Finder ¶
type Finder[T any] struct { Collection *mongo.Collection FilterObj any DBCallbacks *callback.Callback BeforeHooks []BeforeHookFn[T] AfterHooks []AfterHookFn[T] // contains filtered or unexported fields }
func (*Finder[T]) Distinct ¶
func (f *Finder[T]) Distinct(ctx context.Context, fieldName string, opts ...options.Lister[options.DistinctOptions]) *mongo.DistinctResult
func (*Finder[T]) DistinctWithParse ¶
func (f *Finder[T]) DistinctWithParse(ctx context.Context, fieldName string, result any, opts ...options.Lister[options.DistinctOptions]) error
DistinctWithParse is used to parse the result of Distinct result must be a pointer
func (*Finder[T]) FindOneAndUpdate ¶
func (*Finder[T]) GetCollection ¶ added in v2.4.0
func (f *Finder[T]) GetCollection() *mongo.Collection
func (*Finder[T]) PostActionHandler ¶ added in v2.4.0
func (*Finder[T]) PreActionHandler ¶ added in v2.4.0
func (*Finder[T]) RegisterAfterHooks ¶
RegisterAfterHooks is used to set the after hooks of the query If you register the hook for FindOne, the opContext.Docs will be nil If you register the hook for Find, the opContext.Doc will be nil
func (*Finder[T]) RegisterBeforeHooks ¶
func (f *Finder[T]) RegisterBeforeHooks(hooks ...BeforeHookFn[T]) IFinder[T]
type IFinder ¶
type IFinder[T any] interface { FindOne(ctx context.Context, opts ...options.Lister[options.FindOneOptions]) (*T, error) Find(ctx context.Context, opts ...options.Lister[options.FindOptions]) ([]*T, error) Count(ctx context.Context, opts ...options.Lister[options.CountOptions]) (int64, error) Distinct(ctx context.Context, fieldName string, opts ...options.Lister[options.DistinctOptions]) *mongo.DistinctResult DistinctWithParse(ctx context.Context, fieldName string, result any, opts ...options.Lister[options.DistinctOptions]) error Filter(filter any) IFinder[T] FindOneAndUpdate(ctx context.Context, opts ...options.Lister[options.FindOneAndUpdateOptions]) (*T, error) Limit(limit int64) IFinder[T] ModelHook(modelHook any) IFinder[T] RegisterAfterHooks(hooks ...AfterHookFn[T]) IFinder[T] RegisterBeforeHooks(hooks ...BeforeHookFn[T]) IFinder[T] Skip(skip int64) IFinder[T] Sort(sort any) IFinder[T] Updates(update any) IFinder[T] PostActionHandler(ctx context.Context, globalOpContext *operation.OpContext, opContext *OpContext[T], opTypes ...operation.OpType) (err error) PreActionHandler(ctx context.Context, globalOpContext *operation.OpContext, opContext *OpContext[T], opTypes ...operation.OpType) (err error) GetCollection() *mongo.Collection }
type OpContext ¶
type OpContext[T any] struct { Col *mongo.Collection `opt:"-"` Filter any `opt:"-"` Updates any MongoOptions any Fields []*field.Filed ModelHook any StartTime time.Time Doc *T Docs []*T // result of the collection operation Result any }
func NewOpContext ¶
func NewOpContext[T any](col *mongo.Collection, filter any, opts ...OpContextOption[T]) *OpContext[T]
type OpContextOption ¶
func WithDoc ¶
func WithDoc[T any](doc *T) OpContextOption[T]
func WithDocs ¶
func WithDocs[T any](docs []*T) OpContextOption[T]
func WithFields ¶ added in v2.2.0
func WithFields[T any](fields []*field.Filed) OpContextOption[T]
func WithModelHook ¶
func WithModelHook[T any](modelHook any) OpContextOption[T]
func WithMongoOptions ¶
func WithMongoOptions[T any](mongoOptions any) OpContextOption[T]
func WithResult ¶ added in v2.2.0
func WithResult[T any](result any) OpContextOption[T]
func WithStartTime ¶ added in v2.2.0
func WithStartTime[T any](startTime time.Time) OpContextOption[T]
func WithUpdates ¶
func WithUpdates[T any](updates any) OpContextOption[T]
Click to show internal directories.
Click to hide internal directories.