mongo

package
v0.0.0-...-3f93e99 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: GPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToSet

func AddToSet(field string, value interface{}) bson.M

func Compose

func Compose(elements ...bson.DocElem) bson.M

func FromID

func FromID(id string) bson.M

func Insert

func Insert(ctx context.Context, col *mgo.Collection, entity interface{}) error

Insert function

func PipeList

func PipeList(ctx context.Context, col *mgo.Collection, pipeline []bson.M, entity interface{}, visit func(interface{}) error) error

PipeList function

func PipeOne

func PipeOne(ctx context.Context, col *mgo.Collection, pipeline []bson.M, entity interface{}, visit func(interface{}) error) error

PipeOne function

func QueryCount

func QueryCount(ctx context.Context, col *mgo.Collection, criteria interface{}, visit func(int) error) error

QueryCount function

func QueryList

func QueryList(ctx context.Context, col *mgo.Collection, criteria interface{}, entity interface{}, visit func(interface{}) error) error

QueryList function

func QueryOne

func QueryOne(ctx context.Context, col *mgo.Collection, criteria interface{}, entity interface{}, visit func(interface{}) error) error

QueryOne function

func Remove

func Remove(ctx context.Context, col *mgo.Collection, criteria interface{}) error

Remove function

func RemoveFromSet

func RemoveFromSet(field string, value interface{}) bson.M

func Set

func Set(field string, value interface{}) bson.M

func Update

func Update(ctx context.Context, col *mgo.Collection, criteria interface{}, entity interface{}) error

Update function

Types

type ContextFactory

type ContextFactory interface {
	Context(context.Context) (context.Context, error)
}

ContextFactory interface

func CreateContextFactory

func CreateContextFactory(p SessionProvider, l logger.Logger) ContextFactory

CreateContextFactory instance

type Operation

type Operation func(*mgo.Collection) error

Operation to be performed on mongo collection

type OperationContext

type OperationContext struct {
	context.Context
	// contains filtered or unexported fields
}

OperationContext declares operation context

func CreateOperationContext

func CreateOperationContext(ctx context.Context, db string, col string) *OperationContext

CreateOperationContext creates OperationContext

type OperationExecutor

type OperationExecutor interface {
	Execute(*OperationContext, Operation) error
}

OperationExecutor executes operation

func CreateExecutor

func CreateExecutor(p SessionProvider, l logger.Logger) OperationExecutor

CreateExecutor instance

type Option

type Option func(*options)

Option initializes options properties

func WithAuthDb

func WithAuthDb(db string) Option

WithAuthDb initializes authdb option

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger initializes logger option

func WithPassword

func WithPassword(p string) Option

WithPassword initializes password option

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout initializes timeout

func WithURL

func WithURL(u string) Option

WithURL initializes url option

func WithUser

func WithUser(u string) Option

WithUser initializes user option

type Repository

type Repository struct {
	logger.Logger
	// contains filtered or unexported fields
}

Repository type

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, entity interface{}) (string, error)

Create new document

func (*Repository) Execute

func (r *Repository) Execute(ctx context.Context, o Operation) error

func (*Repository) Remove

func (r *Repository) Remove(ctx context.Context, id string) error

Remove document by id

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, id string, op bson.M) error

Update document

type RepositoryFactory

type RepositoryFactory struct {
	logger.Logger
	OperationExecutor
	// contains filtered or unexported fields
}

RepositoryFactory type

func CreateRepositoryFactory

func CreateRepositoryFactory(db string, e OperationExecutor, l logger.Logger) *RepositoryFactory

CreateRepositoryFactory creates repository factory

func (*RepositoryFactory) CreateRepository

func (f *RepositoryFactory) CreateRepository(col string) *Repository

CreateRepository creates new repository

type Session

type Session interface {
	Session() *mgo.Session
	Close(bool)
}

func FromContext

func FromContext(ctx context.Context) Session

FromContext gets mongo session from context

func GetSession

func GetSession(providers ...SessionProvider) Session

type SessionFactory

type SessionFactory interface {
	Session() (*mgo.Session, error)
}

SessionFactory interface

func CreateSessionFactory

func CreateSessionFactory(opts ...Option) SessionFactory

CreateSessionFactory instance

type SessionProvider

type SessionProvider interface {
	Provide() Session
}

SessionProvider interface

func CreateContextSessionProvider

func CreateContextSessionProvider(c context.Context, l logger.Logger) SessionProvider

CreateContextSessionProvider instance

func CreateCopySessionProvider

func CreateCopySessionProvider(p SessionProvider, l logger.Logger) SessionProvider

CreateCopySessionProvider instance

func CreateSessionProvider

func CreateSessionProvider(f SessionFactory, l logger.Logger) SessionProvider

CreateSessionProvider instance

Jump to

Keyboard shortcuts

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