finder

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterHookFn added in v2.4.0

type AfterHookFn[T any] func(ctx context.Context, opContext *OpContext[T], opts ...any) error

type BeforeHookFn added in v2.4.0

type BeforeHookFn[T any] func(ctx context.Context, opContext *OpContext[T], opts ...any) error

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 NewFinder

func NewFinder[T any](collection *mongo.Collection, callbacks *callback.Callback, fields []*field.Filed) *Finder[T]

func (*Finder[T]) Count

func (f *Finder[T]) Count(ctx context.Context, opts ...options.Lister[options.CountOptions]) (int64, error)

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]) Filter

func (f *Finder[T]) Filter(filter any) IFinder[T]

Filter is used to set the filter of the query

func (*Finder[T]) Find

func (f *Finder[T]) Find(ctx context.Context, opts ...options.Lister[options.FindOptions]) ([]*T, error)

func (*Finder[T]) FindOne

func (f *Finder[T]) FindOne(ctx context.Context, opts ...options.Lister[options.FindOneOptions]) (*T, error)

func (*Finder[T]) FindOneAndUpdate

func (f *Finder[T]) FindOneAndUpdate(ctx context.Context, opts ...options.Lister[options.FindOneAndUpdateOptions]) (*T, error)

func (*Finder[T]) GetCollection added in v2.4.0

func (f *Finder[T]) GetCollection() *mongo.Collection

func (*Finder[T]) Limit added in v2.1.0

func (f *Finder[T]) Limit(limit int64) IFinder[T]

func (*Finder[T]) ModelHook

func (f *Finder[T]) ModelHook(modelHook any) IFinder[T]

func (*Finder[T]) PostActionHandler added in v2.4.0

func (f *Finder[T]) PostActionHandler(ctx context.Context, globalOpContext *operation.OpContext, opContext *OpContext[T], opTypes ...operation.OpType) (err error)

func (*Finder[T]) PreActionHandler added in v2.4.0

func (f *Finder[T]) PreActionHandler(ctx context.Context, globalOpContext *operation.OpContext, opContext *OpContext[T], opTypes ...operation.OpType) (err error)

func (*Finder[T]) RegisterAfterHooks

func (f *Finder[T]) RegisterAfterHooks(hooks ...AfterHookFn[T]) IFinder[T]

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]

func (*Finder[T]) Skip added in v2.1.0

func (f *Finder[T]) Skip(skip int64) IFinder[T]

func (*Finder[T]) Sort added in v2.1.0

func (f *Finder[T]) Sort(sort any) IFinder[T]

func (*Finder[T]) Updates

func (f *Finder[T]) Updates(update any) 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

type OpContextOption[T any] func(*OpContext[T])

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]

Jump to

Keyboard shortcuts

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