mongoc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type CachedCollection

type CachedCollection interface {
	Count(query interface{}) (int, error)
	DelCache(keys ...string) error
	FindAllNoCache(v, query interface{}, opts ...QueryOption) error
	FindOne(v interface{}, key string, query interface{}) error
	FindOneNoCache(v, query interface{}) error
	FindOneId(v interface{}, key string, id interface{}) error
	FindOneIdNoCache(v, id interface{}) error
	GetCache(key string, v interface{}) error
	Insert(docs ...interface{}) error
	Pipe(pipeline interface{}) mongo.Pipe
	Remove(selector interface{}, keys ...string) error
	RemoveNoCache(selector interface{}) error
	RemoveAll(selector interface{}, keys ...string) (*mgo.ChangeInfo, error)
	RemoveAllNoCache(selector interface{}) (*mgo.ChangeInfo, error)
	RemoveId(id interface{}, keys ...string) error
	RemoveIdNoCache(id interface{}) error
	SetCache(key string, v interface{}) error
	Update(selector, update interface{}, keys ...string) error
	UpdateNoCache(selector, update interface{}) error
	UpdateId(id, update interface{}, keys ...string) error
	UpdateIdNoCache(id, update interface{}) error
	Upsert(selector, update interface{}, keys ...string) (*mgo.ChangeInfo, error)
	UpsertNoCache(selector, update interface{}) (*mgo.ChangeInfo, error)
}

CachedCollection interface represents a mongo collection with cache.

type Model

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

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

func MustNewModel

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

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

func MustNewNodeModel

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

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

func NewModel

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

NewModel returns a Model with a cache cluster.

func NewNodeModel

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

NewNodeModel returns a Model with a cache node.

func (*Model) Count

func (mm *Model) Count(query interface{}) (int, error)

Count returns the count of given query.

func (*Model) DelCache

func (mm *Model) DelCache(keys ...string) error

DelCache deletes the cache with given keys.

func (*Model) FindAllNoCache

func (mm *Model) FindAllNoCache(v, query interface{}, opts ...QueryOption) error

FindAllNoCache finds all records without cache.

func (*Model) FindOne

func (mm *Model) FindOne(v interface{}, key string, query interface{}) error

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

func (*Model) FindOneId

func (mm *Model) FindOneId(v interface{}, key string, id interface{}) error

FindOneId unmarshals a record into v with query.

func (*Model) FindOneIdNoCache

func (mm *Model) FindOneIdNoCache(v, id interface{}) error

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

func (*Model) FindOneNoCache

func (mm *Model) FindOneNoCache(v, query interface{}) error

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

func (*Model) GetCache

func (mm *Model) GetCache(key string, v interface{}) error

GetCache unmarshal the cache into v with given key.

func (*Model) GetCollection

func (mm *Model) GetCollection(session *mgo.Session) CachedCollection

GetCollection returns a cache collection.

func (*Model) Insert

func (mm *Model) Insert(docs ...interface{}) error

Insert inserts docs.

func (*Model) Pipe

func (mm *Model) Pipe(pipeline interface{}) (mongo.Pipe, error)

Pipe returns a mongo pipe with given pipeline.

func (*Model) Remove

func (mm *Model) Remove(selector interface{}, keys ...string) error

Remove removes a record with given selector, and remove it from cache with given keys.

func (*Model) RemoveAll

func (mm *Model) RemoveAll(selector interface{}, keys ...string) (*mgo.ChangeInfo, error)

RemoveAll removes all records with given selector, and removes cache with given keys.

func (*Model) RemoveAllNoCache

func (mm *Model) RemoveAllNoCache(selector interface{}) (*mgo.ChangeInfo, error)

RemoveAllNoCache removes all records with given selector, and returns a mgo.ChangeInfo.

func (*Model) RemoveId

func (mm *Model) RemoveId(id interface{}, keys ...string) error

RemoveId removes a record with given id, and removes cache with given keys.

func (*Model) RemoveIdNoCache

func (mm *Model) RemoveIdNoCache(id interface{}) error

RemoveIdNoCache removes a record with given id.

func (*Model) RemoveNoCache

func (mm *Model) RemoveNoCache(selector interface{}) error

RemoveNoCache removes a record with given selector.

func (*Model) SetCache

func (mm *Model) SetCache(key string, v interface{}) error

SetCache sets the cache with given key and value.

func (*Model) Update

func (mm *Model) Update(selector, update interface{}, keys ...string) error

Update updates the record with given selector, and delete cache with given keys.

func (*Model) UpdateId

func (mm *Model) UpdateId(id, update interface{}, keys ...string) error

UpdateId updates the record with given id, and delete cache with given keys.

func (*Model) UpdateIdNoCache

func (mm *Model) UpdateIdNoCache(id, update interface{}) error

UpdateIdNoCache updates the record with given id.

func (*Model) UpdateNoCache

func (mm *Model) UpdateNoCache(selector, update interface{}) error

UpdateNoCache updates the record with given selector.

func (*Model) Upsert

func (mm *Model) Upsert(selector, update interface{}, keys ...string) (*mgo.ChangeInfo, error)

Upsert upserts a record with given selector, and delete cache with given keys.

func (*Model) UpsertNoCache

func (mm *Model) UpsertNoCache(selector, update interface{}) (*mgo.ChangeInfo, error)

UpsertNoCache upserts a record with given selector.

type QueryOption

type QueryOption func(query mongo.Query) mongo.Query

QueryOption defines the method to customize a mongo query.

Jump to

Keyboard shortcuts

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