db

package
v2.0.0-alpha5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 18 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"
)

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 ArticleActivator() *di.Activator

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 ChatActivator

func ChatActivator() *di.Activator

func ChatBeforeSave

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

func ChatIndexes

func ChatIndexes(indexView mongo.IndexView) error

func JobActivator

func JobActivator() *di.Activator

func JobIndexes

func JobIndexes(indexView mongo.IndexView) error

func SiteActivator

func SiteActivator() *di.Activator

func SiteIndexes

func SiteIndexes(indexView mongo.IndexView) error

func SysUserActivator

func SysUserActivator() *di.Activator

func SysUserIndexes

func SysUserIndexes(indexView mongo.IndexView) error

func ToNilCloser

func ToNilCloser[T any](value T, err error) (T, di.Closer, error)

Types

type ArticleKey

type ArticleKey struct{}

type ChatKey

type ChatKey struct{}

type JobKey

type JobKey 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 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 Repository

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

func GetArticleRepository

func GetArticleRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Article], error)

func GetChatRepository

func GetChatRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Chat], error)

func GetJobRepository

func GetJobRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Job], error)

func GetSiteRepository

func GetSiteRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.Site], error)

func GetSysUserRepository

func GetSysUserRepository(ctx context.Context, c ...di.Container) (*Repository[*entity.SysUser], error)

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)

type SiteKey

type SiteKey struct{}

type SysUserKey

type SysUserKey struct{}

Jump to

Keyboard shortcuts

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