Documentation ¶
Index ¶
- Constants
- Variables
- func AfterSave[T repository.Entity](entity T, result *mongo.UpdateResult) error
- func ArticleActivator() *di.Activator
- 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 ChatActivator() *di.Activator
- func ChatBeforeSave(entity *entity.Chat) (bson.M, error)
- func ChatIndexes(indexView mongo.IndexView) error
- func JobActivator() *di.Activator
- func JobIndexes(indexView mongo.IndexView) error
- func SiteActivator() *di.Activator
- func SiteIndexes(indexView mongo.IndexView) error
- func SysUserActivator() *di.Activator
- func SysUserIndexes(indexView mongo.IndexView) error
- func ToNilCloser[T any](value T, err error) (T, di.Closer, error)
- type ArticleKey
- type ChatKey
- type JobKey
- 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 Repository
- func GetArticleRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Article], error)
- func GetChatRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Chat], error)
- func GetJobRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Job], error)
- func GetSiteRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Site], error)
- func GetSysUserRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.SysUser], error)
- func NewRepository[T repository.Entity](database *mongodb.Database, collection string, options ...Option[T]) (*Repository[T], error)
- 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)
- type SiteKey
- type SysUserKey
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" )
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 ArticleActivator ¶
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 ChatActivator ¶
func ChatIndexes ¶
func JobActivator ¶
func JobIndexes ¶
func SiteActivator ¶
func SiteIndexes ¶
func SysUserActivator ¶
func SysUserIndexes ¶
Types ¶
type ArticleKey ¶
type ArticleKey struct{}
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 Repository ¶
type Repository[T repository.Entity] struct { // contains filtered or unexported fields }
func GetArticleRepository ¶
func GetChatRepository ¶
func GetJobRepository ¶
func GetSiteRepository ¶
func GetSysUserRepository ¶
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)
type SysUserKey ¶
type SysUserKey struct{}
Click to show internal directories.
Click to hide internal directories.