mongodb

package
v0.0.0-...-087ca59 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFilter

func AddFilter[T any](opts *store.StoreOptions, filter MongoDataFilter)

AddFilter add filter for TEntity

func CheckInsertError

func CheckInsertError(e error) error

func GetClient

func GetClient(opts *MongoOptions) (*mongo.Client, error)

func IDFromHex

func IDFromHex(id string) primitive.ObjectID

func IDString

func IDString(id primitive.ObjectID) string

func MergeFilter

func MergeFilter[T any](ctx context.Context, filter bson.D, opts *store.StoreOptions) bson.D

func MustToId

func MustToId(id *string) primitive.ObjectID

func NewMongoUnitWork

func NewMongoUnitWork() *ginx.UnitWork

func ParseSort

func ParseSort[T any, TKey comparable](s string) bson.D

func ToID

func ToID(id *string) primitive.ObjectID

Types

type Collection

type Collection[TEntity any, TKey comparable] struct {
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection[TEntity any, TKey comparable](c *mongo.Collection, opts *store.StoreOptions) *Collection[TEntity, TKey]

func (*Collection[TEntity, TKey]) Col

func (c *Collection[TEntity, TKey]) Col() *mongo.Collection

func (*Collection[TEntity, TKey]) Count

func (c *Collection[TEntity, TKey]) Count(ctx context.Context, filter bson.D, opts ...*options.CountOptions) (int64, error)

func (*Collection[TEntity, TKey]) DeleteMany

func (c *Collection[TEntity, TKey]) DeleteMany(ctx context.Context, filter bson.D) (int, error)

func (*Collection[TEntity, TKey]) DeleteOne

func (c *Collection[TEntity, TKey]) DeleteOne(ctx context.Context, filter bson.D) (int, error)

func (*Collection[TEntity, TKey]) Find

func (c *Collection[TEntity, TKey]) Find(ctx context.Context, filter bson.D, opts ...*options.FindOptions) ([]*TEntity, error)

func (*Collection[TEntity, TKey]) FindByPage

func (c *Collection[TEntity, TKey]) FindByPage(ctx context.Context, filter bson.D, p *x.PageAndSort, opts ...*options.FindOptions) (*x.PagedResult[*TEntity], error)

func (*Collection[TEntity, TKey]) FindOne

func (c *Collection[TEntity, TKey]) FindOne(ctx context.Context, filter bson.D, opts ...*options.FindOneOptions) (*TEntity, error)

func (*Collection[TEntity, TKey]) GetMany

func (c *Collection[TEntity, TKey]) GetMany(ctx context.Context, ids []TKey) ([]*TEntity, error)

func (*Collection[TEntity, TKey]) Insert

func (c *Collection[TEntity, TKey]) Insert(ctx context.Context, entity *TEntity, opts ...*options.InsertOneOptions) (*TEntity, error)

func (*Collection[TEntity, TKey]) InsertMany

func (c *Collection[TEntity, TKey]) InsertMany(ctx context.Context, entities []*TEntity, ignoreErr bool, opts ...*options.InsertManyOptions) ([]*TEntity, error)

func (*Collection[TEntity, TKey]) MaxOrder

func (c *Collection[TEntity, TKey]) MaxOrder(ctx context.Context, field string, v any) float64

func (*Collection[TEntity, TKey]) MaxOrderMany

func (c *Collection[TEntity, TKey]) MaxOrderMany(ctx context.Context, field string, v any) map[any]float64

func (*Collection[TEntity, TKey]) MergeGlobalFilter

func (c *Collection[TEntity, TKey]) MergeGlobalFilter(ctx context.Context, filter bson.D) bson.D

func (*Collection[TEntity, TKey]) ParseSort

func (c *Collection[TEntity, TKey]) ParseSort(p *x.PageAndSort) bson.D

func (*Collection[TEntity, TKey]) SetAllFilter

func (c *Collection[TEntity, TKey]) SetAllFilter(ctx context.Context, filter bson.D) bson.D

func (*Collection[TEntity, TKey]) SetMultiTenantFilter

func (c *Collection[TEntity, TKey]) SetMultiTenantFilter(ctx context.Context, filter bson.D) bson.D

func (*Collection[TEntity, TKey]) SetSoftDeleteFilter

func (c *Collection[TEntity, TKey]) SetSoftDeleteFilter(filter bson.D) bson.D

func (*Collection[TEntity, TKey]) UpdateByFilter

func (c *Collection[TEntity, TKey]) UpdateByFilter(ctx context.Context, filter bson.D, update interface{}, opts ...*options.UpdateOptions) (int, error)

UpdateMany TODO: 事件改造

func (*Collection[TEntity, TKey]) UpdateMany

func (c *Collection[TEntity, TKey]) UpdateMany(ctx context.Context, filter bson.D, update interface{}, opts ...*options.UpdateOptions) (int, error)

UpdateMany TODO: 事件改造

func (*Collection[TEntity, TKey]) UpdateOne

func (c *Collection[TEntity, TKey]) UpdateOne(ctx context.Context, filter bson.D, entity *TEntity, opts ...*options.UpdateOptions) (int, error)

type Decimal

type Decimal decimal.Decimal

func (Decimal) DecodeValue

func (d Decimal) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

func (Decimal) EncodeValue

func (d Decimal) EncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

type MongoDataFilter

type MongoDataFilter func(ctx context.Context, filter bson.D) bson.D

type MongoOptions

type MongoOptions struct {
	URL    string
	DbName string
}

type MongoRepositoryBase

type MongoRepositoryBase[TEntity any, TKey comparable] struct {
	Options        *MongoOptions
	CollectionName string
	StoreOpts      *store.StoreOptions
}

func NewMongoRepositoryBase

func NewMongoRepositoryBase[TEntity any, TKey comparable](collectionName string) *MongoRepositoryBase[TEntity, TKey]

func (*MongoRepositoryBase[TEntity, TKey]) Collection

func (mr *MongoRepositoryBase[TEntity, TKey]) Collection(ctx context.Context) *Collection[TEntity, TKey]

func (*MongoRepositoryBase[TEntity, TKey]) Count

func (mr *MongoRepositoryBase[TEntity, TKey]) Count(ctx context.Context) (int64, error)

func (*MongoRepositoryBase[TEntity, TKey]) Delete

func (mr *MongoRepositoryBase[TEntity, TKey]) Delete(ctx context.Context, id TKey) (int, error)

func (*MongoRepositoryBase[TEntity, TKey]) DeleteMany

func (mr *MongoRepositoryBase[TEntity, TKey]) DeleteMany(ctx context.Context, ids []TKey) (int, error)

func (*MongoRepositoryBase[TEntity, TKey]) Exists

func (mr *MongoRepositoryBase[TEntity, TKey]) Exists(ctx context.Context, id TKey) (bool, error)

func (*MongoRepositoryBase[TEntity, TKey]) FindByRegex

func (mr *MongoRepositoryBase[TEntity, TKey]) FindByRegex(ctx context.Context, field, regex string, p *x.PageAndSort) (*x.PagedResult[*TEntity], error)

func (*MongoRepositoryBase[TEntity, TKey]) GetById

func (mr *MongoRepositoryBase[TEntity, TKey]) GetById(ctx context.Context, id TKey) (*TEntity, error)

func (*MongoRepositoryBase[TEntity, TKey]) GetCollection

func (mr *MongoRepositoryBase[TEntity, TKey]) GetCollection(ctx context.Context, name string) *mongo.Collection

func (*MongoRepositoryBase[TEntity, TKey]) GetMany

func (mr *MongoRepositoryBase[TEntity, TKey]) GetMany(ctx context.Context, ids []TKey) ([]*TEntity, error)

func (*MongoRepositoryBase[TEntity, TKey]) GetOrNilById

func (mr *MongoRepositoryBase[TEntity, TKey]) GetOrNilById(ctx context.Context, id TKey) (*TEntity, error)

func (*MongoRepositoryBase[TEntity, TKey]) GetPagedList

func (mr *MongoRepositoryBase[TEntity, TKey]) GetPagedList(ctx context.Context, p *x.PageAndSort) (*x.PagedResult[*TEntity], error)

func (*MongoRepositoryBase[TEntity, TKey]) Insert

func (mr *MongoRepositoryBase[TEntity, TKey]) Insert(ctx context.Context, entity *TEntity) (*TEntity, error)

func (*MongoRepositoryBase[TEntity, TKey]) InsertMany

func (mr *MongoRepositoryBase[TEntity, TKey]) InsertMany(ctx context.Context, entities []*TEntity, ignoreErr bool) ([]*TEntity, error)

InsertMany ignoreErr 是否忽略批量插入时的错误, 一般为false, 当导入时忽略重复key的时候可以设为true

func (*MongoRepositoryBase[TEntity, TKey]) MaxOrder

func (mr *MongoRepositoryBase[TEntity, TKey]) MaxOrder(ctx context.Context, field string, v any) float64

func (*MongoRepositoryBase[TEntity, TKey]) MaxOrderMany

func (mr *MongoRepositoryBase[TEntity, TKey]) MaxOrderMany(ctx context.Context, field string, v any) map[any]float64

func (*MongoRepositoryBase[TEntity, TKey]) UpdateById

func (mr *MongoRepositoryBase[TEntity, TKey]) UpdateById(ctx context.Context, id TKey, data *TEntity) (int, error)

type MongoTransactionContext

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

func NewMongoTransactionContext

func NewMongoTransactionContext(ctx mongo.SessionContext) MongoTransactionContext

Jump to

Keyboard shortcuts

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