Documentation ¶
Index ¶
- Constants
- Variables
- func AfterSave[T repository.Entity](entity T, result *mongo.UpdateResult) error
- func ArticleBeforeSave(entity *entity.Article) (bson.M, error)
- func ArticleIndexes(indexView mongo.IndexView) error
- func BeforeSave[T repository.Entity](entity T) (bson.M, error)
- func BuildCriteria(query string, excludeFields ...string) *repository.Criteria
- func ChatBeforeSave(entity *entity.Chat) (bson.M, error)
- func ChatIndexes(indexView mongo.IndexView) error
- func JobIndexes(indexView mongo.IndexView) error
- func SiteIndexes(indexView mongo.IndexView) error
- func SysUserIndexes(indexView mongo.IndexView) error
- type Option
- func WithAfterFind[T repository.Entity](afterFind func(entity T) error) Option[T]
- func WithAfterSave[T repository.Entity](afterSave func(entity T, result *mongo.UpdateResult) error) Option[T]
- func WithBeforeSave[T repository.Entity](beforeSave func(entity T) (bson.M, error)) Option[T]
- func WithEntityFactory[T repository.Entity](entityFactory repository.EntityFactory[T]) Option[T]
- func WithIndexes[T repository.Entity](indexes func(indexView mongo.IndexView) error) Option[T]
- type Plugin
- type Repository
- func (r *Repository[T]) Count(ctx context.Context, filter any) (count int64, err error)
- func (r *Repository[T]) Find(ctx context.Context, criteria *repository.Criteria) ([]T, error)
- func (r *Repository[T]) FindByID(ctx context.Context, id uuid.UUID) (value T, err error)
- func (r *Repository[T]) FindIter(ctx context.Context, criteria *repository.Criteria) (repository.Iter[T], error)
- func (r *Repository[T]) Remove(ctx context.Context, id uuid.UUID) error
- func (r *Repository[T]) Save(ctx context.Context, entity T) (err error)
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 ArticleIndexes ¶
func BeforeSave ¶
func BeforeSave[T repository.Entity](entity T) (bson.M, error)
func BuildCriteria ¶
func BuildCriteria(query string, excludeFields ...string) *repository.Criteria
func ChatIndexes ¶
func JobIndexes ¶
func SiteIndexes ¶
func SysUserIndexes ¶
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 WithEntityFactory ¶
func WithEntityFactory[T repository.Entity](entityFactory repository.EntityFactory[T]) Option[T]
func WithIndexes ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
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]) Find ¶
func (r *Repository[T]) Find(ctx context.Context, criteria *repository.Criteria) ([]T, error)
func (*Repository[T]) FindIter ¶
func (r *Repository[T]) FindIter(ctx context.Context, criteria *repository.Criteria) (repository.Iter[T], error)
Click to show internal directories.
Click to hide internal directories.