db

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryIndex = "index"
	QuerySize  = "size"
	QuerySort  = "sort"
	QueryCond  = "cond"
	QueryField = "field"
	QueryValue = "value"

	CondEmpty = ""
	CondEq    = "eq"
	CondNe    = "ne"
	CondGt    = "gt"
	CondGte   = "gte"
	CondLt    = "lt"
	CondLte   = "lte"
	CondIn    = "in"
	CondNin   = "nin"
	CondRegex = "regex"
	CondLike  = "like"
)
View Source
const PluginName = "mongo"

Variables

View Source
var (
	ErrMissingDB         = errors.New("missing *mongo.Database")
	ErrMissingCollection = errors.New("missing collection name")
)

Functions

func AfterSave

func AfterSave[T repository.Entity](entity T, result *mongo.UpdateResult) error

func ArticleBeforeSave

func ArticleBeforeSave(entity *entity.Article) (bson.M, error)

func ArticleIndexes

func ArticleIndexes(indexView mongo.IndexView) error

func BeforeSave

func BeforeSave[T repository.Entity](entity T) (bson.M, error)

func BuildCriteria

func BuildCriteria(query string, excludeFields ...string) *repository.Criteria

func ChatBeforeSave

func ChatBeforeSave(entity *entity.Chat) (bson.M, error)

func ChatIndexes

func ChatIndexes(indexView mongo.IndexView) error

func JobIndexes

func JobIndexes(indexView mongo.IndexView) error

func SiteIndexes

func SiteIndexes(indexView mongo.IndexView) error

func SysUserIndexes

func SysUserIndexes(indexView mongo.IndexView) error

Types

type Option

type Option[T repository.Entity] func(*Repository[T]) error

func WithAfterFind

func WithAfterFind[T repository.Entity](afterFind func(entity T) error) Option[T]

func WithAfterSave

func WithAfterSave[T repository.Entity](afterSave func(entity T, result *mongo.UpdateResult) error) Option[T]

func WithBeforeSave

func WithBeforeSave[T repository.Entity](beforeSave func(entity T) (bson.M, error)) Option[T]

func WithEntityFactory

func WithEntityFactory[T repository.Entity](entityFactory repository.EntityFactory[T]) Option[T]

func WithIndexes

func WithIndexes[T repository.Entity](indexes func(indexView mongo.IndexView) error) Option[T]

type Plugin

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

func (*Plugin) Init

func (p *Plugin) Init(cfg config.Configurer) error

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Provides

func (p *Plugin) Provides() []*dep.Out

func (*Plugin) Repository

func (p *Plugin) Repository(tp any) (any, error)

func (*Plugin) ServiceUnitOfWork

func (p *Plugin) ServiceUnitOfWork() common.UnitOfWork

type Repository

type Repository[T repository.Entity] struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[T repository.Entity](database *mongodb.Database, collection string, options ...Option[T]) (*Repository[T], error)

func (*Repository[T]) Count

func (r *Repository[T]) Count(ctx context.Context, filter any) (count int64, err error)

func (*Repository[T]) Find

func (r *Repository[T]) Find(ctx context.Context, criteria *repository.Criteria) ([]T, error)

func (*Repository[T]) FindByID

func (r *Repository[T]) FindByID(ctx context.Context, id uuid.UUID) (value T, err error)

func (*Repository[T]) FindIter

func (r *Repository[T]) FindIter(ctx context.Context, criteria *repository.Criteria) (repository.Iter[T], error)

func (*Repository[T]) Remove

func (r *Repository[T]) Remove(ctx context.Context, id uuid.UUID) error

func (*Repository[T]) Save

func (r *Repository[T]) Save(ctx context.Context, entity T) (err error)

Jump to

Keyboard shortcuts

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