Documentation ¶
Index ¶
- func AddFilter[T any](opts *store.StoreOptions, filter MongoDataFilter)
- func CheckInsertError(e error) error
- func GetClient(opts *MongoOptions) (*mongo.Client, error)
- func IDFromHex(id string) primitive.ObjectID
- func IDString(id primitive.ObjectID) string
- func MergeFilter[T any](ctx context.Context, filter bson.D, opts *store.StoreOptions) bson.D
- func MustToId(id *string) primitive.ObjectID
- func NewMongoUnitWork() *ginx.UnitWork
- func ParseSort[T any, TKey comparable](s string) bson.D
- func ToID(id *string) primitive.ObjectID
- type Collection
- func (c *Collection[TEntity, TKey]) Col() *mongo.Collection
- func (c *Collection[TEntity, TKey]) Count(ctx context.Context, filter bson.D, opts ...*options.CountOptions) (int64, error)
- func (c *Collection[TEntity, TKey]) DeleteMany(ctx context.Context, filter bson.D) (int, error)
- func (c *Collection[TEntity, TKey]) DeleteOne(ctx context.Context, filter bson.D) (int, error)
- func (c *Collection[TEntity, TKey]) Find(ctx context.Context, filter bson.D, opts ...*options.FindOptions) ([]*TEntity, error)
- func (c *Collection[TEntity, TKey]) FindByPage(ctx context.Context, filter bson.D, p *x.PageAndSort, ...) (*x.PagedResult[*TEntity], error)
- func (c *Collection[TEntity, TKey]) FindOne(ctx context.Context, filter bson.D, opts ...*options.FindOneOptions) (*TEntity, error)
- func (c *Collection[TEntity, TKey]) GetMany(ctx context.Context, ids []TKey) ([]*TEntity, error)
- func (c *Collection[TEntity, TKey]) Insert(ctx context.Context, entity *TEntity, opts ...*options.InsertOneOptions) (*TEntity, error)
- func (c *Collection[TEntity, TKey]) InsertMany(ctx context.Context, entities []*TEntity, ignoreErr bool, ...) ([]*TEntity, error)
- func (c *Collection[TEntity, TKey]) MaxOrder(ctx context.Context, field string, v any) float64
- func (c *Collection[TEntity, TKey]) MaxOrderMany(ctx context.Context, field string, v any) map[any]float64
- func (c *Collection[TEntity, TKey]) MergeGlobalFilter(ctx context.Context, filter bson.D) bson.D
- func (c *Collection[TEntity, TKey]) ParseSort(p *x.PageAndSort) bson.D
- func (c *Collection[TEntity, TKey]) SetAllFilter(ctx context.Context, filter bson.D) bson.D
- func (c *Collection[TEntity, TKey]) SetMultiTenantFilter(ctx context.Context, filter bson.D) bson.D
- func (c *Collection[TEntity, TKey]) SetSoftDeleteFilter(filter bson.D) bson.D
- func (c *Collection[TEntity, TKey]) UpdateByFilter(ctx context.Context, filter bson.D, update interface{}, ...) (int, error)
- func (c *Collection[TEntity, TKey]) UpdateMany(ctx context.Context, filter bson.D, update interface{}, ...) (int, error)
- func (c *Collection[TEntity, TKey]) UpdateOne(ctx context.Context, filter bson.D, entity *TEntity, ...) (int, error)
- type Decimal
- type MongoDataFilter
- type MongoOptions
- type MongoRepositoryBase
- func (mr *MongoRepositoryBase[TEntity, TKey]) Collection(ctx context.Context) *Collection[TEntity, TKey]
- func (mr *MongoRepositoryBase[TEntity, TKey]) Count(ctx context.Context) (int64, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) Delete(ctx context.Context, id TKey) (int, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) DeleteMany(ctx context.Context, ids []TKey) (int, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) Exists(ctx context.Context, id TKey) (bool, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) FindByRegex(ctx context.Context, field, regex string, p *x.PageAndSort) (*x.PagedResult[*TEntity], error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) GetById(ctx context.Context, id TKey) (*TEntity, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) GetCollection(ctx context.Context, name string) *mongo.Collection
- func (mr *MongoRepositoryBase[TEntity, TKey]) GetMany(ctx context.Context, ids []TKey) ([]*TEntity, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) GetOrNilById(ctx context.Context, id TKey) (*TEntity, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) GetPagedList(ctx context.Context, p *x.PageAndSort) (*x.PagedResult[*TEntity], error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) Insert(ctx context.Context, entity *TEntity) (*TEntity, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) InsertMany(ctx context.Context, entities []*TEntity, ignoreErr bool) ([]*TEntity, error)
- func (mr *MongoRepositoryBase[TEntity, TKey]) MaxOrder(ctx context.Context, field string, v any) float64
- func (mr *MongoRepositoryBase[TEntity, TKey]) MaxOrderMany(ctx context.Context, field string, v any) map[any]float64
- func (mr *MongoRepositoryBase[TEntity, TKey]) UpdateById(ctx context.Context, id TKey, data *TEntity) (int, error)
- type MongoTransactionContext
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 MergeFilter ¶
func NewMongoUnitWork ¶
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 (*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]) MaxOrderMany ¶
func (*Collection[TEntity, TKey]) MergeGlobalFilter ¶
func (*Collection[TEntity, TKey]) ParseSort ¶
func (c *Collection[TEntity, TKey]) ParseSort(p *x.PageAndSort) bson.D
func (*Collection[TEntity, TKey]) SetAllFilter ¶
func (*Collection[TEntity, TKey]) SetMultiTenantFilter ¶
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: 事件改造
type 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 MongoOptions ¶
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]) MaxOrderMany ¶
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
Click to show internal directories.
Click to hide internal directories.