monc

package
v1.11.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is an alias of mongo.ErrNoDocuments.
	ErrNotFound = mongo.ErrNoDocuments
)

Functions

This section is empty.

Types

type Model

type Model struct {
	*mon.Model
	// contains filtered or unexported fields
}

A Model is a mongo model that built with cache capability.

func MustNewModel

func MustNewModel(uri, db, collection string, c cache.CacheConf, opts ...cache.Option) *Model

MustNewModel returns a Model with a cache cluster, exists on errors.

func MustNewNodeModel

func MustNewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) *Model

MustNewNodeModel returns a Model with a cache node, exists on errors.

func NewModel

func NewModel(uri, db, collection string, conf cache.CacheConf, opts ...cache.Option) (*Model, error)

NewModel returns a Model with a cache cluster.

func NewModelWithCache

func NewModelWithCache(uri, db, collection string, c cache.Cache) (*Model, error)

NewModelWithCache returns a Model with a custom cache.

func NewNodeModel

func NewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) (*Model, error)

NewNodeModel returns a Model with a cache node.

func (*Model) DelCache

func (mm *Model) DelCache(ctx context.Context, keys ...string) error

DelCache deletes the cache with given keys.

func (*Model) DeleteOne

func (mm *Model) DeleteOne(ctx context.Context, key string, filter any,
	opts ...*mopt.DeleteOptions) (int64, error)

DeleteOne deletes the document with given filter, and remove it from cache.

func (*Model) DeleteOneNoCache

func (mm *Model) DeleteOneNoCache(ctx context.Context, filter any,
	opts ...*mopt.DeleteOptions) (int64, error)

DeleteOneNoCache deletes the document with given filter.

func (*Model) FindOne

func (mm *Model) FindOne(ctx context.Context, key string, v, filter any,
	opts ...*mopt.FindOneOptions) error

FindOne unmarshals a record into v with given key and query.

func (*Model) FindOneAndDelete

func (mm *Model) FindOneAndDelete(ctx context.Context, key string, v, filter any,
	opts ...*mopt.FindOneAndDeleteOptions) error

FindOneAndDelete deletes the document with given filter, and unmarshals it into v.

func (*Model) FindOneAndDeleteNoCache

func (mm *Model) FindOneAndDeleteNoCache(ctx context.Context, v, filter any,
	opts ...*mopt.FindOneAndDeleteOptions) error

FindOneAndDeleteNoCache deletes the document with given filter, and unmarshals it into v.

func (*Model) FindOneAndReplace

func (mm *Model) FindOneAndReplace(ctx context.Context, key string, v, filter any,
	replacement any, opts ...*mopt.FindOneAndReplaceOptions) error

FindOneAndReplace replaces the document with given filter with replacement, and unmarshals it into v.

func (*Model) FindOneAndReplaceNoCache

func (mm *Model) FindOneAndReplaceNoCache(ctx context.Context, v, filter any,
	replacement any, opts ...*mopt.FindOneAndReplaceOptions) error

FindOneAndReplaceNoCache replaces the document with given filter with replacement, and unmarshals it into v.

func (*Model) FindOneAndUpdate

func (mm *Model) FindOneAndUpdate(ctx context.Context, key string, v, filter any,
	update any, opts ...*mopt.FindOneAndUpdateOptions) error

FindOneAndUpdate updates the document with given filter with update, and unmarshals it into v.

func (*Model) FindOneAndUpdateNoCache

func (mm *Model) FindOneAndUpdateNoCache(ctx context.Context, v, filter any,
	update any, opts ...*mopt.FindOneAndUpdateOptions) error

FindOneAndUpdateNoCache updates the document with given filter with update, and unmarshals it into v.

func (*Model) FindOneNoCache

func (mm *Model) FindOneNoCache(ctx context.Context, v, filter any,
	opts ...*mopt.FindOneOptions) error

FindOneNoCache unmarshals a record into v with query, without cache.

func (*Model) GetCache

func (mm *Model) GetCache(key string, v any) error

GetCache unmarshal the cache into v with given key.

func (*Model) InsertOne

func (mm *Model) InsertOne(ctx context.Context, key string, document any,
	opts ...*mopt.InsertOneOptions) (*mongo.InsertOneResult, error)

InsertOne inserts a single document into the collection, and remove the cache placeholder.

func (*Model) InsertOneNoCache

func (mm *Model) InsertOneNoCache(ctx context.Context, document any,
	opts ...*mopt.InsertOneOptions) (*mongo.InsertOneResult, error)

InsertOneNoCache inserts a single document into the collection.

func (*Model) ReplaceOne

func (mm *Model) ReplaceOne(ctx context.Context, key string, filter, replacement any,
	opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error)

ReplaceOne replaces a single document in the collection, and remove the cache.

func (*Model) ReplaceOneNoCache

func (mm *Model) ReplaceOneNoCache(ctx context.Context, filter, replacement any,
	opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error)

ReplaceOneNoCache replaces a single document in the collection.

func (*Model) SetCache

func (mm *Model) SetCache(key string, v any) error

SetCache sets the cache with given key and value.

func (*Model) UpdateByID

func (mm *Model) UpdateByID(ctx context.Context, key string, id, update any,
	opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)

UpdateByID updates the document with given id with update, and remove the cache.

func (*Model) UpdateByIDNoCache

func (mm *Model) UpdateByIDNoCache(ctx context.Context, id, update any,
	opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)

UpdateByIDNoCache updates the document with given id with update.

func (*Model) UpdateMany

func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter, update any,
	opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)

UpdateMany updates the documents that match filter with update, and remove the cache.

func (*Model) UpdateManyNoCache

func (mm *Model) UpdateManyNoCache(ctx context.Context, filter, update any,
	opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)

UpdateManyNoCache updates the documents that match filter with update.

func (*Model) UpdateOne

func (mm *Model) UpdateOne(ctx context.Context, key string, filter, update any,
	opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOne updates the first document that matches filter with update, and remove the cache.

func (*Model) UpdateOneNoCache

func (mm *Model) UpdateOneNoCache(ctx context.Context, filter, update any,
	opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)

UpdateOneNoCache updates the first document that matches filter with update.

Jump to

Keyboard shortcuts

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