Documentation ¶
Index ¶
- Variables
- type Model
- func MustNewModel(uri, db, collection string, c cache.CacheConf, opts ...cache.Option) *Model
- func MustNewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) *Model
- func NewModel(uri, db, collection string, conf cache.CacheConf, opts ...cache.Option) (*Model, error)
- func NewModelWithCache(uri, db, collection string, c cache.Cache) (*Model, error)
- func NewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) (*Model, error)
- func (mm *Model) DelCache(ctx context.Context, keys ...string) error
- func (mm *Model) DeleteOne(ctx context.Context, key string, filter any, opts ...*mopt.DeleteOptions) (int64, error)
- func (mm *Model) DeleteOneNoCache(ctx context.Context, filter any, opts ...*mopt.DeleteOptions) (int64, error)
- func (mm *Model) FindOne(ctx context.Context, key string, v, filter any, opts ...*mopt.FindOneOptions) error
- func (mm *Model) FindOneAndDelete(ctx context.Context, key string, v, filter any, ...) error
- func (mm *Model) FindOneAndDeleteNoCache(ctx context.Context, v, filter any, opts ...*mopt.FindOneAndDeleteOptions) error
- func (mm *Model) FindOneAndReplace(ctx context.Context, key string, v, filter any, replacement any, ...) error
- func (mm *Model) FindOneAndReplaceNoCache(ctx context.Context, v, filter any, replacement any, ...) error
- func (mm *Model) FindOneAndUpdate(ctx context.Context, key string, v, filter any, update any, ...) error
- func (mm *Model) FindOneAndUpdateNoCache(ctx context.Context, v, filter any, update any, ...) error
- func (mm *Model) FindOneNoCache(ctx context.Context, v, filter any, opts ...*mopt.FindOneOptions) error
- func (mm *Model) GetCache(key string, v any) error
- func (mm *Model) InsertOne(ctx context.Context, key string, document any, opts ...*mopt.InsertOneOptions) (*mongo.InsertOneResult, error)
- func (mm *Model) InsertOneNoCache(ctx context.Context, document any, opts ...*mopt.InsertOneOptions) (*mongo.InsertOneResult, error)
- func (mm *Model) ReplaceOne(ctx context.Context, key string, filter, replacement any, ...) (*mongo.UpdateResult, error)
- func (mm *Model) ReplaceOneNoCache(ctx context.Context, filter, replacement any, opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error)
- func (mm *Model) SetCache(key string, v any) error
- func (mm *Model) UpdateByID(ctx context.Context, key string, id, update any, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
- func (mm *Model) UpdateByIDNoCache(ctx context.Context, id, update any, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
- func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter, update any, ...) (*mongo.UpdateResult, error)
- func (mm *Model) UpdateManyNoCache(ctx context.Context, filter, update any, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
- func (mm *Model) UpdateOne(ctx context.Context, key string, filter, update any, ...) (*mongo.UpdateResult, error)
- func (mm *Model) UpdateOneNoCache(ctx context.Context, filter, update any, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is an alias of mongo.ErrNoDocuments. ErrNotFound = mongo.ErrNoDocuments )
Functions ¶
This section is empty.
Types ¶
type Model ¶
A Model is a mongo model that built with cache capability.
func MustNewModel ¶
MustNewModel returns a Model with a cache cluster, exists on errors.
func MustNewNodeModel ¶
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 ¶
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) 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) 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) 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.