finder

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterOpContext added in v0.12.0

type AfterOpContext[T any] struct {
	*OpContext `opt:"-"`
	Doc        *T
	Docs       []*T
}

func NewAfterOpContext added in v0.12.0

func NewAfterOpContext[T any](opContext *OpContext, opts ...AfterOpContextOption[T]) *AfterOpContext[T]

type AfterOpContextOption added in v0.12.0

type AfterOpContextOption[T any] func(*AfterOpContext[T])

func WithDoc added in v0.12.0

func WithDoc[T any](doc *T) AfterOpContextOption[T]

func WithDocs added in v0.12.0

func WithDocs[T any](docs []*T) AfterOpContextOption[T]

type Finder

type Finder[T any] struct {
	// contains filtered or unexported fields
}

func NewFinder

func NewFinder[T any](collection *mongo.Collection) *Finder[T]

func (*Finder[T]) Count added in v0.0.4

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

func (*Finder[T]) Distinct added in v0.11.0

func (f *Finder[T]) Distinct(ctx context.Context, fieldName string, opts ...*options.DistinctOptions) ([]any, error)

func (*Finder[T]) DistinctWithParse added in v0.11.0

func (f *Finder[T]) DistinctWithParse(ctx context.Context, fieldName string, result any, opts ...*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) *Finder[T]

Filter is used to set the filter of the query

func (*Finder[T]) Find added in v0.0.7

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

func (*Finder[T]) FindOne

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

func (*Finder[T]) FindOneAndUpdate added in v1.2.0

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

func (*Finder[T]) ModelHook added in v1.4.0

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

func (*Finder[T]) RegisterAfterHooks added in v0.12.0

func (f *Finder[T]) RegisterAfterHooks(hooks ...afterHookFn[T]) *Finder[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 added in v0.12.0

func (f *Finder[T]) RegisterBeforeHooks(hooks ...beforeHookFn) *Finder[T]

func (*Finder[T]) Updates added in v1.2.0

func (f *Finder[T]) Updates(update any) *Finder[T]

type IFinder added in v1.7.0

type IFinder[T any] interface {
	FindOne(ctx context.Context, opts ...*options.FindOneOptions) (*T, error)
	Find(ctx context.Context, opts ...*options.FindOptions) ([]*T, error)
	Count(ctx context.Context, opts ...*options.CountOptions) (int64, error)
	Distinct(ctx context.Context, fieldName string, opts ...*options.DistinctOptions) ([]any, error)
	DistinctWithParse(ctx context.Context, fieldName string, result any, opts ...*options.DistinctOptions) error
	FindOneAndUpdate(ctx context.Context, opts ...*options.FindOneAndUpdateOptions) (*T, error)
}

type IllegalUser added in v1.0.0

type IllegalUser struct {
	ID   primitive.ObjectID `bson:"_id,omitempty"`
	Name string             `bson:"name"`
	Age  string
}

type OpContext added in v0.12.0

type OpContext struct {
	Col          *mongo.Collection `opt:"-"`
	Filter       any               `opt:"-"`
	Updates      any
	MongoOptions any
	ModelHook    any
}

func NewOpContext added in v0.12.0

func NewOpContext(col *mongo.Collection, filter any, opts ...OpContextOption) *OpContext

type OpContextOption added in v0.12.0

type OpContextOption func(*OpContext)

func WithModelHook added in v1.4.0

func WithModelHook(modelHook any) OpContextOption

func WithMongoOptions added in v1.3.0

func WithMongoOptions(mongoOptions any) OpContextOption

func WithUpdates added in v1.2.0

func WithUpdates(updates any) OpContextOption

type TestTempUser added in v1.0.0

type TestTempUser struct {
	Id           string `bson:"_id"`
	Name         string `bson:"name"`
	Age          int64
	UnknownField string `bson:"-"`
}

type TestUser added in v1.0.0

type TestUser struct {
	ID           primitive.ObjectID `bson:"_id,omitempty"`
	Name         string             `bson:"name"`
	Age          int64
	UnknownField string    `bson:"-"`
	CreatedAt    time.Time `bson:"created_at"`
	UpdatedAt    time.Time `bson:"updated_at"`
}

func (*TestUser) DefaultCreatedAt added in v1.0.0

func (tu *TestUser) DefaultCreatedAt()

func (*TestUser) DefaultUpdatedAt added in v1.0.0

func (tu *TestUser) DefaultUpdatedAt()

type UpdatedUser added in v1.0.0

type UpdatedUser struct {
	Name string `bson:"name"`
	Age  int64
}

type UserName added in v1.0.0

type UserName struct {
	Name string `bson:"name"`
}

Jump to

Keyboard shortcuts

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