mongo

package
v0.0.0-...-a5125b8 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSortOpts

func GetSortOpts(s sort2.Sort) *options.FindOptions

GetSortOpts 获取排序选项 @param sortStr 排序字符串: "id,desc"

Types

type DocumentRepository

type DocumentRepository[Entity ce.Entity] struct {
	AutoConvertId2ObjectId bool
	// contains filtered or unexported fields
}

func NewDocumentRepository

func NewDocumentRepository[E ce.Entity](db *mongo.Database, collectionName string, collectionOpts ...*options.CollectionOptions) *DocumentRepository[E]

NewDocumentRepository creates a new DocumentRepository.

func NewDocumentRepositoryWithEntity

func NewDocumentRepositoryWithEntity[E ce.Entity](db *mongo.Database, emptyEntity any, collectionOpts ...*options.CollectionOptions) *DocumentRepository[E]

NewDocumentRepositoryWithEntity creates a new DocumentRepository.

func (*DocumentRepository[Entity]) Count

func (d *DocumentRepository[Entity]) Count(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)

func (*DocumentRepository[Entity]) Delete

func (d *DocumentRepository[Entity]) Delete(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (int64, error)

func (*DocumentRepository[Entity]) DeleteById

func (d *DocumentRepository[Entity]) DeleteById(ctx context.Context, id interface{}) (bool, error)

func (*DocumentRepository[Entity]) Exist

func (d *DocumentRepository[Entity]) Exist(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (bool, error)

func (*DocumentRepository[Entity]) ExistsById

func (d *DocumentRepository[Entity]) ExistsById(ctx context.Context, id interface{}) (bool, error)

func (*DocumentRepository[Entity]) Find

func (d *DocumentRepository[Entity]) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) ([]*Entity, error)

func (*DocumentRepository[Entity]) FindAll

func (d *DocumentRepository[Entity]) FindAll(ctx context.Context) ([]*Entity, error)

func (*DocumentRepository[Entity]) FindById

func (d *DocumentRepository[Entity]) FindById(ctx context.Context, id interface{}) (*Entity, error)

func (*DocumentRepository[Entity]) FindOne

func (d *DocumentRepository[Entity]) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (*Entity, error)

func (*DocumentRepository[Entity]) FindOneAndModify

func (d *DocumentRepository[Entity]) FindOneAndModify(ctx context.Context, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) (*Entity, error)

func (*DocumentRepository[Entity]) FindWithCursor

func (d *DocumentRepository[Entity]) FindWithCursor(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)

func (*DocumentRepository[Entity]) GetId

func (d *DocumentRepository[Entity]) GetId(id interface{}) interface{}

func (*DocumentRepository[Entity]) QueryWithPage

func (d *DocumentRepository[Entity]) QueryWithPage(ctx context.Context, filter interface{}, pageable *page.Pageable) (*page.Page[Entity], error)

QueryWithPage 分页查询

func (*DocumentRepository[Entity]) QueryWithSort

func (d *DocumentRepository[Entity]) QueryWithSort(ctx context.Context, filter interface{}, sort *sort.Sort) ([]*Entity, error)

QueryWithSort 排序查询

func (*DocumentRepository[Entity]) Save

func (d *DocumentRepository[Entity]) Save(ctx context.Context, entity *Entity) (*Entity, error)

func (*DocumentRepository[Entity]) SaveMany

func (d *DocumentRepository[Entity]) SaveMany(ctx context.Context, entities []*Entity) ([]*Entity, error)

func (*DocumentRepository[Entity]) UpdateMany

func (d *DocumentRepository[Entity]) UpdateMany(ctx context.Context, filter interface{}, update interface{},
	opts ...*options.UpdateOptions) (int64, error)

func (*DocumentRepository[Entity]) UpdateOne

func (d *DocumentRepository[Entity]) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (int64, error)

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

func NewQueryBuilder

func NewQueryBuilder() *QueryBuilder

func Of

func Of(filter bson.M) *QueryBuilder

func (*QueryBuilder) And

func (b *QueryBuilder) And(conditions ...interface{}) *QueryBuilder

And 构建AND查询条件

func (*QueryBuilder) Between

func (b *QueryBuilder) Between(field string, min interface{}, max interface{}) *QueryBuilder

Between 构建区间查询条件

func (*QueryBuilder) Build

func (b *QueryBuilder) Build() interface{}

func (*QueryBuilder) Exists

func (b *QueryBuilder) Exists(field string, exists bool) *QueryBuilder

Exists 构建存在查询条件

func (*QueryBuilder) Gt

func (b *QueryBuilder) Gt(field string, value interface{}) *QueryBuilder

Gt 构建大于查询条件

func (*QueryBuilder) Gte

func (b *QueryBuilder) Gte(field string, value interface{}) *QueryBuilder

Gte 构建大于等于查询条件

func (*QueryBuilder) Is

func (b *QueryBuilder) Is(field string, value interface{}) *QueryBuilder

Is 构建等于查询条件

func (*QueryBuilder) LeftLike

func (b *QueryBuilder) LeftLike(field string, value string) *QueryBuilder

LeftLike 构建左模糊查询条件

func (*QueryBuilder) Like

func (b *QueryBuilder) Like(field string, value string) *QueryBuilder

Like 构建模糊查询条件

func (*QueryBuilder) Lt

func (b *QueryBuilder) Lt(field string, value interface{}) *QueryBuilder

Lt 构建小于查询条件

func (*QueryBuilder) Lte

func (b *QueryBuilder) Lte(field string, value interface{}) *QueryBuilder

Lte 构建小于等于查询条件

func (*QueryBuilder) Ne

func (b *QueryBuilder) Ne(field string, value interface{}) *QueryBuilder

Ne 构建不等于查询��件

func (*QueryBuilder) Or

func (b *QueryBuilder) Or(conditions ...interface{}) *QueryBuilder

Or 构建OR查询条件

func (*QueryBuilder) RightLike

func (b *QueryBuilder) RightLike(field string, value string) *QueryBuilder

RightLike 构建右模糊查询条件

type Repository

type Repository[Entity interface{}] interface {
	repository.CrudRepository[Entity]
	SaveMany(ctx context.Context, entities []*Entity) ([]*Entity, error)
	// Find 根据条件查询数据
	Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) ([]*Entity, error)

	// FindOne 查找单挑数据
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (*Entity, error)

	FindOneAndModify(ctx context.Context, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) (*Entity, error)

	// Count 统计数据
	Count(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)

	// Exist 存在
	Exist(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (bool, error)

	Delete(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (int64, error)

	// QueryWithPage 分页查询
	QueryWithPage(ctx context.Context, filter interface{}, pageable *page.Pageable) (*page.Page[Entity], error)

	// QueryWithSort 排序查询
	QueryWithSort(ctx context.Context, filter interface{}, sort *sort.Sort) ([]*Entity, error)
}

Jump to

Keyboard shortcuts

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