mongo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package mongo is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = mgo.ErrNotFound

ErrNotFound is an alias of mgo.ErrNotFound.

Functions

func FormatAddr

func FormatAddr(hosts []string) string

FormatAddr formats mongo hosts to a string.

Types

type BulkInserter

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

A BulkInserter is used to insert bulk of mongo records.

func NewBulkInserter

func NewBulkInserter(session *mgo.Session, dbName string, collectionNamer func() string) *BulkInserter

NewBulkInserter returns a BulkInserter.

func (*BulkInserter) Flush

func (bi *BulkInserter) Flush()

Flush flushes the inserter, writes all pending records.

func (*BulkInserter) Insert

func (bi *BulkInserter) Insert(doc interface{})

Insert inserts doc.

func (*BulkInserter) SetResultHandler

func (bi *BulkInserter) SetResultHandler(handler ResultHandler)

SetResultHandler sets the result handler.

type ClosableIter

type ClosableIter struct {
	Iter
	Cleanup func()
}

A ClosableIter is a closable mongo iter.

func (*ClosableIter) Close

func (it *ClosableIter) Close() error

Close closes a mongo iter.

type Collection

type Collection interface {
	Find(query interface{}) Query
	FindId(id interface{}) Query
	Insert(docs ...interface{}) error
	Pipe(pipeline interface{}) Pipe
	Remove(selector interface{}) error
	RemoveAll(selector interface{}) (*mgo.ChangeInfo, error)
	RemoveId(id interface{}) error
	Update(selector, update interface{}) error
	UpdateId(id, update interface{}) error
	Upsert(selector, update interface{}) (*mgo.ChangeInfo, error)
}

Collection interface represents a mongo connection.

type Iter

type Iter interface {
	All(result interface{}) error
	Close() error
	Done() bool
	Err() error
	For(result interface{}, f func() error) error
	Next(result interface{}) bool
	State() (int64, []bson.Raw)
	Timeout() bool
}

Iter interface represents a mongo iter.

type MockIter

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

MockIter is a mock of Iter interface

func NewMockIter

func NewMockIter(ctrl *gomock.Controller) *MockIter

NewMockIter creates a new mock instance

func (*MockIter) All

func (m *MockIter) All(result interface{}) error

All mocks base method

func (*MockIter) Close

func (m *MockIter) Close() error

Close mocks base method

func (*MockIter) Done

func (m *MockIter) Done() bool

Done mocks base method

func (*MockIter) EXPECT

func (m *MockIter) EXPECT() *MockIterMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockIter) Err

func (m *MockIter) Err() error

Err mocks base method

func (*MockIter) For

func (m *MockIter) For(result interface{}, f func() error) error

For mocks base method

func (*MockIter) Next

func (m *MockIter) Next(result interface{}) bool

Next mocks base method

func (*MockIter) State

func (m *MockIter) State() (int64, []bson.Raw)

State mocks base method

func (*MockIter) Timeout

func (m *MockIter) Timeout() bool

Timeout mocks base method

type MockIterMockRecorder

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

MockIterMockRecorder is the mock recorder for MockIter

func (*MockIterMockRecorder) All

func (mr *MockIterMockRecorder) All(result interface{}) *gomock.Call

All indicates an expected call of All

func (*MockIterMockRecorder) Close

func (mr *MockIterMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close

func (*MockIterMockRecorder) Done

func (mr *MockIterMockRecorder) Done() *gomock.Call

Done indicates an expected call of Done

func (*MockIterMockRecorder) Err

func (mr *MockIterMockRecorder) Err() *gomock.Call

Err indicates an expected call of Err

func (*MockIterMockRecorder) For

func (mr *MockIterMockRecorder) For(result, f interface{}) *gomock.Call

For indicates an expected call of For

func (*MockIterMockRecorder) Next

func (mr *MockIterMockRecorder) Next(result interface{}) *gomock.Call

Next indicates an expected call of Next

func (*MockIterMockRecorder) State

func (mr *MockIterMockRecorder) State() *gomock.Call

State indicates an expected call of State

func (*MockIterMockRecorder) Timeout

func (mr *MockIterMockRecorder) Timeout() *gomock.Call

Timeout indicates an expected call of Timeout

type Model

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

A Model is a mongo model.

func MustNewModel

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

MustNewModel returns a Model, exits on errors.

func NewModel

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

NewModel returns a Model.

func (*Model) Find

func (mm *Model) Find(query interface{}) (Query, error)

Find finds a record with given query.

func (*Model) FindId

func (mm *Model) FindId(id interface{}) (Query, error)

FindId finds a record with given id.

func (*Model) GetCollection

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

GetCollection returns a Collection with given session.

func (*Model) Insert

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

Insert inserts docs into mm.

func (*Model) Pipe

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

Pipe returns a Pipe with given pipeline.

func (*Model) PutSession

func (mm *Model) PutSession(session *mgo.Session)

PutSession returns the given session.

func (*Model) Remove

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

Remove removes the records with given selector.

func (*Model) RemoveAll

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

RemoveAll removes all with given selector and returns a mgo.ChangeInfo.

func (*Model) RemoveId

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

RemoveId removes a record with given id.

func (*Model) TakeSession

func (mm *Model) TakeSession() (*mgo.Session, error)

TakeSession gets a session.

func (*Model) Update

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

Update updates a record with given selector.

func (*Model) UpdateId

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

UpdateId updates a record with given id.

func (*Model) Upsert

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

Upsert upserts a record with given selector, and returns a mgo.ChangeInfo.

type Option

type Option func(opts *options)

Option defines the method to customize a mongo model.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout customizes an operation with given timeout.

type Pipe

type Pipe interface {
	All(result interface{}) error
	AllowDiskUse() Pipe
	Batch(n int) Pipe
	Collation(collation *mgo.Collation) Pipe
	Explain(result interface{}) error
	Iter() Iter
	One(result interface{}) error
	SetMaxTime(d time.Duration) Pipe
}

Pipe interface represents a mongo pipe.

type Query

type Query interface {
	All(result interface{}) error
	Apply(change mgo.Change, result interface{}) (*mgo.ChangeInfo, error)
	Batch(n int) Query
	Collation(collation *mgo.Collation) Query
	Comment(comment string) Query
	Count() (int, error)
	Distinct(key string, result interface{}) error
	Explain(result interface{}) error
	For(result interface{}, f func() error) error
	Hint(indexKey ...string) Query
	Iter() Iter
	Limit(n int) Query
	LogReplay() Query
	MapReduce(job *mgo.MapReduce, result interface{}) (*mgo.MapReduceInfo, error)
	One(result interface{}) error
	Prefetch(p float64) Query
	Select(selector interface{}) Query
	SetMaxScan(n int) Query
	SetMaxTime(d time.Duration) Query
	Skip(n int) Query
	Snapshot() Query
	Sort(fields ...string) Query
	Tail(timeout time.Duration) Iter
}

Query interface represents a mongo query.

type ResultHandler

type ResultHandler func(*mgo.BulkResult, error)

ResultHandler is a handler that used to handle results.

Directories

Path Synopsis
Package internal is a generated GoMock package.
Package internal is a generated GoMock package.

Jump to

Keyboard shortcuts

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